home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / breakpoi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  87.5 KB  |  3,342 lines

  1. /* Everything about breakpoints, for GDB.
  2.    Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include <ctype.h>
  22. #include "symtab.h"
  23. #include "frame.h"
  24. #include "breakpoint.h"
  25. #include "gdbtypes.h"
  26. #include "expression.h"
  27. #include "gdbcore.h"
  28. #include "gdbcmd.h"
  29. #include "value.h"
  30. #include "ctype.h"
  31. #include "command.h"
  32. #include "inferior.h"
  33. #include "thread.h"
  34. #include "target.h"
  35. #include "language.h"
  36. #include <string.h>
  37. #include "demangle.h"
  38.  
  39. /* local function prototypes */
  40.  
  41. static void
  42. catch_command_1 PARAMS ((char *, int, int));
  43.  
  44. static void
  45. enable_delete_command PARAMS ((char *, int));
  46.  
  47. static void
  48. enable_delete_breakpoint PARAMS ((struct breakpoint *));
  49.  
  50. static void
  51. enable_once_command PARAMS ((char *, int));
  52.  
  53. static void
  54. enable_once_breakpoint PARAMS ((struct breakpoint *));
  55.  
  56. static void
  57. disable_command PARAMS ((char *, int));
  58.  
  59. static void
  60. disable_breakpoint PARAMS ((struct breakpoint *));
  61.  
  62. static void
  63. enable_command PARAMS ((char *, int));
  64.  
  65. static void
  66. enable_breakpoint PARAMS ((struct breakpoint *));
  67.  
  68. static void
  69. map_breakpoint_numbers PARAMS ((char *,    void (*)(struct breakpoint *)));
  70.  
  71. static void
  72. ignore_command PARAMS ((char *, int));
  73.  
  74. static int
  75. breakpoint_re_set_one PARAMS ((char *));
  76.  
  77. static void
  78. delete_command PARAMS ((char *, int));
  79.  
  80. static void
  81. clear_command PARAMS ((char *, int));
  82.  
  83. static void
  84. catch_command PARAMS ((char *, int));
  85.  
  86. static struct symtabs_and_lines
  87. get_catch_sals PARAMS ((int));
  88.  
  89. static void
  90. watch_command PARAMS ((char *, int));
  91.  
  92. static void
  93. tbreak_command PARAMS ((char *, int));
  94.  
  95. static void
  96. break_command_1 PARAMS ((char *, int, int));
  97.  
  98. static void
  99. mention PARAMS ((struct breakpoint *));
  100.  
  101. static struct breakpoint *
  102. set_raw_breakpoint PARAMS ((struct symtab_and_line));
  103.  
  104. static void
  105. check_duplicates PARAMS ((CORE_ADDR));
  106.  
  107. static void
  108. describe_other_breakpoints PARAMS ((CORE_ADDR));
  109.  
  110. static void
  111. breakpoints_info PARAMS ((char *, int));
  112.  
  113. static void
  114. breakpoint_1 PARAMS ((int, int));
  115.  
  116. static bpstat
  117. bpstat_alloc PARAMS ((struct breakpoint *, bpstat));
  118.  
  119. static int
  120. breakpoint_cond_eval PARAMS ((char *));
  121.  
  122. static void
  123. cleanup_executing_breakpoints PARAMS ((int));
  124.  
  125. static void
  126. commands_command PARAMS ((char *, int));
  127.  
  128. static void
  129. condition_command PARAMS ((char *, int));
  130.  
  131. static int
  132. get_number PARAMS ((char **));
  133.  
  134. static void
  135. set_breakpoint_count PARAMS ((int));
  136.  
  137.  
  138. extern int addressprint;        /* Print machine addresses? */
  139. extern int demangle;            /* Print de-mangled symbol names? */
  140.  
  141. /* Are we executing breakpoint commands?  */
  142. static int executing_breakpoint_commands;
  143.  
  144. /* Walk the following statement or block through all breakpoints.
  145.    ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
  146.    breakpoint.  */
  147.  
  148. #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
  149.  
  150. #define ALL_BREAKPOINTS_SAFE(b,tmp)    \
  151.     for (b = breakpoint_chain;    \
  152.          b? (tmp=b->next, 1): 0;    \
  153.          b = tmp)
  154.  
  155. /* Chain of all breakpoints defined.  */
  156.  
  157. static struct breakpoint *breakpoint_chain;
  158.  
  159. /* Number of last breakpoint made.  */
  160.  
  161. static int breakpoint_count;
  162.  
  163. /* Set breakpoint count to NUM.  */
  164. static void
  165. set_breakpoint_count (num)
  166.      int num;
  167. {
  168.   breakpoint_count = num;
  169.   set_internalvar (lookup_internalvar ("bpnum"),
  170.            value_from_longest (builtin_type_int, (LONGEST) num));
  171. }
  172.  
  173. /* Default address, symtab and line to put a breakpoint at
  174.    for "break" command with no arg.
  175.    if default_breakpoint_valid is zero, the other three are
  176.    not valid, and "break" with no arg is an error.
  177.  
  178.    This set by print_stack_frame, which calls set_default_breakpoint.  */
  179.  
  180. int default_breakpoint_valid;
  181. CORE_ADDR default_breakpoint_address;
  182. struct symtab *default_breakpoint_symtab;
  183. int default_breakpoint_line;
  184.  
  185. /* Flag indicating extra verbosity for xgdb.  */
  186. extern int xgdb_verbose;
  187.  
  188. /* *PP is a string denoting a breakpoint.  Get the number of the breakpoint.
  189.    Advance *PP after the string and any trailing whitespace.
  190.  
  191.    Currently the string can either be a number or "$" followed by the name
  192.    of a convenience variable.  Making it an expression wouldn't work well
  193.    for map_breakpoint_numbers (e.g. "4 + 5 + 6").  */
  194. static int
  195. get_number (pp)
  196.      char **pp;
  197. {
  198.   int retval;
  199.   char *p = *pp;
  200.  
  201.   if (p == NULL)
  202.     /* Empty line means refer to the last breakpoint.  */
  203.     return breakpoint_count;
  204.   else if (*p == '$')
  205.     {
  206.       /* Make a copy of the name, so we can null-terminate it
  207.      to pass to lookup_internalvar().  */
  208.       char *varname;
  209.       char *start = ++p;
  210.       value val;
  211.  
  212.       while (isalnum (*p) || *p == '_')
  213.     p++;
  214.       varname = (char *) alloca (p - start + 1);
  215.       strncpy (varname, start, p - start);
  216.       varname[p - start] = '\0';
  217.       val = value_of_internalvar (lookup_internalvar (varname));
  218.       if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
  219.     error (
  220. "Convenience variables used to specify breakpoints must have integer values."
  221.            );
  222.       retval = (int) value_as_long (val);
  223.     }
  224.   else
  225.     {
  226.       if (*p == '-')
  227.     ++p;
  228.       while (*p >= '0' && *p <= '9')
  229.     ++p;
  230.       if (p == *pp)
  231.     /* There is no number here.  (e.g. "cond a == b").  */
  232.     error_no_arg ("breakpoint number");
  233.       retval = atoi (*pp);
  234.     }
  235.   if (!(isspace (*p) || *p == '\0'))
  236.     error ("breakpoint number expected");
  237.   while (isspace (*p))
  238.     p++;
  239.   *pp = p;
  240.   return retval;
  241. }
  242.  
  243. /* condition N EXP -- set break condition of breakpoint N to EXP.  */
  244.  
  245. static void
  246. condition_command (arg, from_tty)
  247.      char *arg;
  248.      int from_tty;
  249. {
  250.   register struct breakpoint *b;
  251.   char *p;
  252.   register int bnum;
  253.  
  254.   if (arg == 0)
  255.     error_no_arg ("breakpoint number");
  256.  
  257.   p = arg;
  258.   bnum = get_number (&p);
  259.  
  260.   ALL_BREAKPOINTS (b)
  261.     if (b->number == bnum)
  262.       {
  263.     if (b->cond)
  264.       {
  265.         free ((PTR)b->cond);
  266.         b->cond = 0;
  267.       }
  268.     if (b->cond_string != NULL)
  269.       free ((PTR)b->cond_string);
  270.  
  271.     if (*p == 0)
  272.       {
  273.         b->cond = 0;
  274.         b->cond_string = NULL;
  275.         if (from_tty)
  276.           printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
  277.       }
  278.     else
  279.       {
  280.         arg = p;
  281.         /* I don't know if it matters whether this is the string the user
  282.            typed in or the decompiled expression.  */
  283.         b->cond_string = savestring (arg, strlen (arg));
  284.         b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
  285.         if (*arg)
  286.           error ("Junk at end of expression");
  287.       }
  288.     return;
  289.       }
  290.  
  291.   error ("No breakpoint number %d.", bnum);
  292. }
  293.  
  294. /* ARGSUSED */
  295. static void
  296. commands_command (arg, from_tty)
  297.      char *arg;
  298.      int from_tty;
  299. {
  300.   register struct breakpoint *b;
  301.   char *p;
  302.   register int bnum;
  303.   struct command_line *l;
  304.  
  305.   /* If we allowed this, we would have problems with when to
  306.      free the storage, if we change the commands currently
  307.      being read from.  */
  308.  
  309.   if (executing_breakpoint_commands)
  310.     error ("Can't use the \"commands\" command among a breakpoint's commands.");
  311.  
  312.   p = arg;
  313.   bnum = get_number (&p);
  314.   if (p && *p)
  315.     error ("Unexpected extra arguments following breakpoint number.");
  316.       
  317.   ALL_BREAKPOINTS (b)
  318.     if (b->number == bnum)
  319.       {
  320.     if (from_tty && input_from_terminal_p ())
  321.       printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
  322. End with a line saying just \"end\".\n", bnum);
  323.     l = read_command_lines ();
  324.     free_command_lines (&b->commands);
  325.     b->commands = l;
  326.     return;
  327.       }
  328.   error ("No breakpoint number %d.", bnum);
  329. }
  330.  
  331. extern int memory_breakpoint_size; /* from mem-break.c */
  332.  
  333. /* Like target_read_memory() but if breakpoints are inserted, return
  334.    the shadow contents instead of the breakpoints themselves.
  335.  
  336.    Read "memory data" from whatever target or inferior we have. 
  337.    Returns zero if successful, errno value if not.  EIO is used
  338.    for address out of bounds.  If breakpoints are inserted, returns
  339.    shadow contents, not the breakpoints themselves.  From breakpoint.c.  */
  340.  
  341. int
  342. read_memory_nobpt (memaddr, myaddr, len)
  343.      CORE_ADDR memaddr;
  344.      char *myaddr;
  345.      unsigned len;
  346. {
  347.   int status;
  348.   struct breakpoint *b;
  349.  
  350.   if (memory_breakpoint_size < 0)
  351.     /* No breakpoints on this machine.  FIXME: This should be
  352.        dependent on the debugging target.  Probably want
  353.        target_insert_breakpoint to return a size, saying how many
  354.        bytes of the shadow contents are used, or perhaps have
  355.        something like target_xfer_shadow.  */
  356.     return target_read_memory (memaddr, myaddr, len);
  357.   
  358.   ALL_BREAKPOINTS (b)
  359.     {
  360.       if (b->type == bp_watchpoint || !b->inserted)
  361.     continue;
  362.       else if (b->address + memory_breakpoint_size <= memaddr)
  363.     /* The breakpoint is entirely before the chunk of memory
  364.        we are reading.  */
  365.     continue;
  366.       else if (b->address >= memaddr + len)
  367.     /* The breakpoint is entirely after the chunk of memory we
  368.        are reading.  */
  369.     continue;
  370.       else
  371.     {
  372.       /* Copy the breakpoint from the shadow contents, and recurse
  373.          for the things before and after.  */
  374.       
  375.       /* Addresses and length of the part of the breakpoint that
  376.          we need to copy.  */
  377.       CORE_ADDR membpt = b->address;
  378.       unsigned int bptlen = memory_breakpoint_size;
  379.       /* Offset within shadow_contents.  */
  380.       int bptoffset = 0;
  381.       
  382.       if (membpt < memaddr)
  383.         {
  384.           /* Only copy the second part of the breakpoint.  */
  385.           bptlen -= memaddr - membpt;
  386.           bptoffset = memaddr - membpt;
  387.           membpt = memaddr;
  388.         }
  389.  
  390.       if (membpt + bptlen > memaddr + len)
  391.         {
  392.           /* Only copy the first part of the breakpoint.  */
  393.           bptlen -= (membpt + bptlen) - (memaddr + len);
  394.         }
  395.  
  396.       memcpy (myaddr + membpt - memaddr, 
  397.           b->shadow_contents + bptoffset, bptlen);
  398.  
  399.       if (membpt > memaddr)
  400.         {
  401.           /* Copy the section of memory before the breakpoint.  */
  402.           status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
  403.           if (status != 0)
  404.         return status;
  405.         }
  406.  
  407.       if (membpt + bptlen < memaddr + len)
  408.         {
  409.           /* Copy the section of memory after the breakpoint.  */
  410.           status = read_memory_nobpt
  411.         (membpt + bptlen,
  412.          myaddr + membpt + bptlen - memaddr,
  413.          memaddr + len - (membpt + bptlen));
  414.           if (status != 0)
  415.         return status;
  416.         }
  417.       return 0;
  418.     }
  419.     }
  420.   /* Nothing overlaps.  Just call read_memory_noerr.  */
  421.   return target_read_memory (memaddr, myaddr, len);
  422. }
  423.  
  424. /* insert_breakpoints is used when starting or continuing the program.
  425.    remove_breakpoints is used when the program stops.
  426.    Both return zero if successful,
  427.    or an `errno' value if could not write the inferior.  */
  428.  
  429. int
  430. insert_breakpoints ()
  431. {
  432.   register struct breakpoint *b;
  433.   int val = 0;
  434.   int disabled_breaks = 0;
  435.  
  436.   ALL_BREAKPOINTS (b)
  437.     if (b->type != bp_watchpoint
  438.     && b->enable != disabled
  439.     && ! b->inserted
  440.     && ! b->duplicate)
  441.       {
  442.     val = target_insert_breakpoint(b->address, b->shadow_contents);
  443.     if (val)
  444.       {
  445.         /* Can't set the breakpoint.  */
  446. #if defined (DISABLE_UNSETTABLE_BREAK)
  447.         if (DISABLE_UNSETTABLE_BREAK (b->address))
  448.           {
  449.         val = 0;
  450.         b->enable = disabled;
  451.         if (!disabled_breaks)
  452.           {
  453.             target_terminal_ours_for_output ();
  454.             fprintf_unfiltered (gdb_stderr,
  455.              "Cannot insert breakpoint %d:\n", b->number);
  456.             printf_filtered ("Disabling shared library breakpoints:\n");
  457.           }
  458.         disabled_breaks = 1;
  459.         printf_filtered ("%d ", b->number);
  460.           }
  461.         else
  462. #endif
  463.           {
  464.         target_terminal_ours_for_output ();
  465.         fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
  466. #ifdef ONE_PROCESS_WRITETEXT
  467.         fprintf_unfiltered (gdb_stderr,
  468.           "The same program may be running in another process.\n");
  469. #endif
  470.         memory_error (val, b->address);    /* which bombs us out */
  471.           }
  472.       }
  473.     else
  474.       b->inserted = 1;
  475.       }
  476.   if (disabled_breaks)
  477.     printf_filtered ("\n");
  478.   return val;
  479. }
  480.  
  481. int
  482. remove_breakpoints ()
  483. {
  484.   register struct breakpoint *b;
  485.   int val;
  486.  
  487. #ifdef BREAKPOINT_DEBUG
  488.   printf_unfiltered ("Removing breakpoints.\n");
  489. #endif /* BREAKPOINT_DEBUG */
  490.  
  491.   ALL_BREAKPOINTS (b)
  492.     if (b->type != bp_watchpoint && b->inserted)
  493.       {
  494.     val = target_remove_breakpoint(b->address, b->shadow_contents);
  495.     if (val)
  496.       return val;
  497.     b->inserted = 0;
  498. #ifdef BREAKPOINT_DEBUG
  499.     printf_unfiltered ("Removed breakpoint at %s",
  500.         local_hex_string((unsigned long) b->address));
  501.     printf_unfiltered (", shadow %s",
  502.         local_hex_string((unsigned long) b->shadow_contents[0]));
  503.     printf_unfiltered (", %s.\n",
  504.         local_hex_string((unsigned long) b->shadow_contents[1]));
  505. #endif /* BREAKPOINT_DEBUG */
  506.       }
  507.  
  508.   return 0;
  509. }
  510.  
  511. /* Clear the "inserted" flag in all breakpoints.  */
  512.  
  513. void
  514. mark_breakpoints_out ()
  515. {
  516.   register struct breakpoint *b;
  517.  
  518.   ALL_BREAKPOINTS (b)
  519.     b->inserted = 0;
  520. }
  521.  
  522. /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
  523.    which should go away between runs of the program.  */
  524.  
  525. void
  526. breakpoint_init_inferior ()
  527. {
  528.   register struct breakpoint *b, *temp;
  529.  
  530.   ALL_BREAKPOINTS_SAFE (b, temp)
  531.     {
  532.       b->inserted = 0;
  533.  
  534.       /* If the call dummy breakpoint is at the entry point it will
  535.      cause problems when the inferior is rerun, so we better
  536.      get rid of it.  */
  537.       if (b->type == bp_call_dummy)
  538.     delete_breakpoint (b);
  539.     }
  540. }
  541.  
  542. /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
  543.    When continuing from a location with a breakpoint,
  544.    we actually single step once before calling insert_breakpoints.  */
  545.  
  546. int
  547. breakpoint_here_p (pc)
  548.      CORE_ADDR pc;
  549. {
  550.   register struct breakpoint *b;
  551.  
  552.   ALL_BREAKPOINTS (b)
  553.     if (b->enable != disabled && b->address == pc)
  554.       return 1;
  555.  
  556.   return 0;
  557. }
  558.  
  559. /* Return nonzero if FRAME is a dummy frame.  We can't use PC_IN_CALL_DUMMY
  560.    because figuring out the saved SP would take too much time, at least using
  561.    get_saved_register on the 68k.  This means that for this function to
  562.    work right a port must use the bp_call_dummy breakpoint.  */
  563.  
  564. int
  565. frame_in_dummy (frame)
  566.      FRAME frame;
  567. {
  568.   struct breakpoint *b;
  569.  
  570. #ifdef CALL_DUMMY
  571.   ALL_BREAKPOINTS (b)
  572.     {
  573.       static unsigned LONGEST dummy[] = CALL_DUMMY;
  574.  
  575.       if (b->type == bp_call_dummy
  576.       && b->frame == frame->frame
  577.  
  578.       /* We need to check the PC as well as the frame on the sparc,
  579.          for signals.exp in the testsuite.  */
  580.       && (frame->pc
  581.           >= (b->address
  582.           - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE))
  583.       && frame->pc <= b->address)
  584.     return 1;
  585.     }
  586. #endif /* CALL_DUMMY */
  587.   return 0;
  588. }
  589.  
  590. /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
  591.    is valid for process/thread PID.  */
  592.  
  593. int
  594. breakpoint_thread_match (pc, pid)
  595.      CORE_ADDR pc;
  596.      int pid;
  597. {
  598.   struct breakpoint *b;
  599.   int thread;
  600.  
  601.   thread = pid_to_thread_id (pid);
  602.  
  603.   ALL_BREAKPOINTS (b)
  604.     if (b->enable != disabled
  605.     && b->address == pc
  606.     && (b->thread == -1 || b->thread == thread))
  607.       return 1;
  608.  
  609.   return 0;
  610. }
  611.  
  612.  
  613. /* bpstat stuff.  External routines' interfaces are documented
  614.    in breakpoint.h.  */
  615.  
  616. /* Clear a bpstat so that it says we are not at any breakpoint.
  617.    Also free any storage that is part of a bpstat.  */
  618.  
  619. void
  620. bpstat_clear (bsp)
  621.      bpstat *bsp;
  622. {
  623.   bpstat p;
  624.   bpstat q;
  625.  
  626.   if (bsp == 0)
  627.     return;
  628.   p = *bsp;
  629.   while (p != NULL)
  630.     {
  631.       q = p->next;
  632.       if (p->old_val != NULL)
  633.     value_free (p->old_val);
  634.       free ((PTR)p);
  635.       p = q;
  636.     }
  637.   *bsp = NULL;
  638. }
  639.  
  640. /* Return a copy of a bpstat.  Like "bs1 = bs2" but all storage that
  641.    is part of the bpstat is copied as well.  */
  642.  
  643. bpstat
  644. bpstat_copy (bs)
  645.      bpstat bs;
  646. {
  647.   bpstat p = NULL;
  648.   bpstat tmp;
  649.   bpstat retval = NULL;
  650.  
  651.   if (bs == NULL)
  652.     return bs;
  653.  
  654.   for (; bs != NULL; bs = bs->next)
  655.     {
  656.       tmp = (bpstat) xmalloc (sizeof (*tmp));
  657.       memcpy (tmp, bs, sizeof (*tmp));
  658.       if (p == NULL)
  659.     /* This is the first thing in the chain.  */
  660.     retval = tmp;
  661.       else
  662.     p->next = tmp;
  663.       p = tmp;
  664.     }
  665.   p->next = NULL;
  666.   return retval;
  667. }
  668.  
  669. /* Find the bpstat associated with this breakpoint */
  670.  
  671. bpstat
  672. bpstat_find_breakpoint(bsp, breakpoint)
  673.      bpstat bsp;
  674.      struct breakpoint *breakpoint;
  675. {
  676.   if (bsp == NULL) return NULL;
  677.  
  678.   for (;bsp != NULL; bsp = bsp->next) {
  679.     if (bsp->breakpoint_at == breakpoint) return bsp;
  680.   }
  681.   return NULL;
  682. }
  683.  
  684. /* Return the breakpoint number of the first breakpoint we are stopped
  685.    at.  *BSP upon return is a bpstat which points to the remaining
  686.    breakpoints stopped at (but which is not guaranteed to be good for
  687.    anything but further calls to bpstat_num).
  688.    Return 0 if passed a bpstat which does not indicate any breakpoints.  */
  689.  
  690. int
  691. bpstat_num (bsp)
  692.      bpstat *bsp;
  693. {
  694.   struct breakpoint *b;
  695.  
  696.   if ((*bsp) == NULL)
  697.     return 0;            /* No more breakpoint values */
  698.   else
  699.     {
  700.       b = (*bsp)->breakpoint_at;
  701.       *bsp = (*bsp)->next;
  702.       if (b == NULL)
  703.     return -1;        /* breakpoint that's been deleted since */
  704.       else
  705.         return b->number;    /* We have its number */
  706.     }
  707. }
  708.  
  709. /* Modify BS so that the actions will not be performed.  */
  710.  
  711. void
  712. bpstat_clear_actions (bs)
  713.      bpstat bs;
  714. {
  715.   for (; bs != NULL; bs = bs->next)
  716.     {
  717.       bs->commands = NULL;
  718.       if (bs->old_val != NULL)
  719.     {
  720.       value_free (bs->old_val);
  721.       bs->old_val = NULL;
  722.     }
  723.     }
  724. }
  725.  
  726. /* Stub for cleaning up our state if we error-out of a breakpoint command */
  727. /* ARGSUSED */
  728. static void
  729. cleanup_executing_breakpoints (ignore)
  730.      int ignore;
  731. {
  732.   executing_breakpoint_commands = 0;
  733. }
  734.  
  735. /* Execute all the commands associated with all the breakpoints at this
  736.    location.  Any of these commands could cause the process to proceed
  737.    beyond this point, etc.  We look out for such changes by checking
  738.    the global "breakpoint_proceeded" after each command.  */
  739.  
  740. void
  741. bpstat_do_actions (bsp)
  742.      bpstat *bsp;
  743. {
  744.   bpstat bs;
  745.   struct cleanup *old_chain;
  746.  
  747.   executing_breakpoint_commands = 1;
  748.   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
  749.  
  750. top:
  751.   bs = *bsp;
  752.  
  753.   breakpoint_proceeded = 0;
  754.   for (; bs != NULL; bs = bs->next)
  755.     {
  756.       while (bs->commands)
  757.     {
  758.       char *line = bs->commands->line;
  759.       bs->commands = bs->commands->next;
  760.       execute_command (line, 0);
  761.       /* If the inferior is proceeded by the command, bomb out now.
  762.          The bpstat chain has been blown away by wait_for_inferior.
  763.          But since execution has stopped again, there is a new bpstat
  764.          to look at, so start over.  */
  765.       if (breakpoint_proceeded)
  766.         goto top;
  767.     }
  768.     }
  769.  
  770.   executing_breakpoint_commands = 0;
  771.   discard_cleanups (old_chain);
  772. }
  773.  
  774. /* This is the normal print_it function for a bpstat.  In the future,
  775.    much of this logic could (should?) be moved to bpstat_stop_status,
  776.    by having it set different print_it functions.  */
  777.  
  778. static int
  779. print_it_normal (bs)
  780.      bpstat bs;
  781. {
  782.   /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
  783.      which has since been deleted.  */
  784.   if (bs->breakpoint_at == NULL
  785.       || (bs->breakpoint_at->type != bp_breakpoint
  786.       && bs->breakpoint_at->type != bp_watchpoint))
  787.     return 0;
  788.  
  789.   if (bs->breakpoint_at->type == bp_breakpoint)
  790.     {
  791.       /* I think the user probably only wants to see one breakpoint
  792.      number, not all of them.  */
  793.       printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
  794.       return 0;
  795.     }
  796.       
  797.   if (bs->old_val != NULL)
  798.     {
  799.       printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
  800.       print_expression (bs->breakpoint_at->exp, gdb_stdout);
  801.       printf_filtered ("\nOld value = ");
  802.       value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default);
  803.       printf_filtered ("\nNew value = ");
  804.       value_print (bs->breakpoint_at->val, gdb_stdout, 0,
  805.            Val_pretty_default);
  806.       printf_filtered ("\n");
  807.       value_free (bs->old_val);
  808.       bs->old_val = NULL;
  809.       return 0;
  810.     }
  811.   /* We can't deal with it.  Maybe another member of the bpstat chain can.  */
  812.   return -1;
  813. }
  814.  
  815. /* Print a message indicating what happened.  Returns nonzero to
  816.    say that only the source line should be printed after this (zero
  817.    return means print the frame as well as the source line).  */
  818. /* Currently we always return zero.  */
  819. int
  820. bpstat_print (bs)
  821.      bpstat bs;
  822. {
  823.   int val;
  824.   
  825.   if (bs == NULL)
  826.     return 0;
  827.  
  828.   val = (*bs->print_it) (bs);
  829.   if (val >= 0)
  830.     return val;
  831.   
  832.   /* Maybe another breakpoint in the chain caused us to stop.
  833.      (Currently all watchpoints go on the bpstat whether hit or
  834.      not.  That probably could (should) be changed, provided care is taken
  835.      with respect to bpstat_explains_signal).  */
  836.   if (bs->next)
  837.     return bpstat_print (bs->next);
  838.  
  839.   /* We reached the end of the chain without printing anything.  */
  840.   return 0;
  841. }
  842.  
  843. /* Evaluate the expression EXP and return 1 if value is zero.
  844.    This is used inside a catch_errors to evaluate the breakpoint condition. 
  845.    The argument is a "struct expression *" that has been cast to char * to 
  846.    make it pass through catch_errors.  */
  847.  
  848. static int
  849. breakpoint_cond_eval (exp)
  850.      char *exp;
  851. {
  852.   return !value_true (evaluate_expression ((struct expression *)exp));
  853. }
  854.  
  855. /* Allocate a new bpstat and chain it to the current one.  */
  856.  
  857. static bpstat
  858. bpstat_alloc (b, cbs)
  859.      register struct breakpoint *b;
  860.      bpstat cbs;            /* Current "bs" value */
  861. {
  862.   bpstat bs;
  863.  
  864.   bs = (bpstat) xmalloc (sizeof (*bs));
  865.   cbs->next = bs;
  866.   bs->breakpoint_at = b;
  867.   /* If the condition is false, etc., don't do the commands.  */
  868.   bs->commands = NULL;
  869.   bs->old_val = NULL;
  870.   bs->print_it = print_it_normal;
  871.   return bs;
  872. }
  873.  
  874. /* Return the frame which we can use to evaluate the expression
  875.    whose valid block is valid_block, or NULL if not in scope.
  876.  
  877.    This whole concept is probably not the way to do things (it is incredibly
  878.    slow being the main reason, not to mention fragile (e.g. the sparc
  879.    frame pointer being fetched as 0 bug causes it to stop)).  Instead,
  880.    introduce a version of "struct frame" which survives over calls to the
  881.    inferior, but which is better than FRAME_ADDR in the sense that it lets
  882.    us evaluate expressions relative to that frame (on some machines, it
  883.    can just be a FRAME_ADDR).  Save one of those instead of (or in addition
  884.    to) the exp_valid_block, and then use it to evaluate the watchpoint
  885.    expression, with no need to do all this backtracing every time.
  886.  
  887.    Or better yet, what if it just copied the struct frame and its next
  888.    frame?  Off the top of my head, I would think that would work
  889.    because things like (a29k) rsize and msize, or (sparc) bottom just
  890.    depend on the frame, and aren't going to be different just because
  891.    the inferior has done something.  Trying to recalculate them
  892.    strikes me as a lot of work, possibly even impossible.  Saving the
  893.    next frame is needed at least on a29k, where get_saved_register
  894.    uses fi->next->saved_msp.  For figuring out whether that frame is
  895.    still on the stack, I guess this needs to be machine-specific (e.g.
  896.    a29k) but I think
  897.  
  898.       read_fp () INNER_THAN watchpoint_frame->frame
  899.  
  900.    would generally work.
  901.  
  902.    Of course the scope of the expression could be less than a whole
  903.    function; perhaps if the innermost frame is the one which the
  904.    watchpoint is relative to (another machine-specific thing, usually
  905.  
  906.       FRAMELESS_FUNCTION_INVOCATION (get_current_frame(), fromleaf)
  907.       read_fp () == wp_frame->frame
  908.       && !fromleaf
  909.  
  910.    ), *then* it could do a
  911.  
  912.       contained_in (get_current_block (), wp->exp_valid_block).
  913.  
  914.       */
  915.  
  916. FRAME
  917. within_scope (valid_block)
  918.      struct block *valid_block;
  919. {
  920.   FRAME fr = get_current_frame ();
  921.   struct frame_info *fi = get_frame_info (fr);
  922.   CORE_ADDR func_start;
  923.  
  924.   /* If caller_pc_valid is true, we are stepping through
  925.      a function prologue, which is bounded by callee_func_start
  926.      (inclusive) and callee_prologue_end (exclusive).
  927.      caller_pc is the pc of the caller.
  928.  
  929.      Yes, this is hairy.  */
  930.   static int caller_pc_valid = 0;
  931.   static CORE_ADDR caller_pc;
  932.   static CORE_ADDR callee_func_start;
  933.   static CORE_ADDR callee_prologue_end;
  934.   
  935.   find_pc_partial_function (fi->pc, (PTR)NULL, &func_start, (CORE_ADDR *)NULL);
  936.   func_start += FUNCTION_START_OFFSET;
  937.   if (fi->pc == func_start)
  938.     {
  939.       /* We just called a function.  The only other case I
  940.      can think of where the pc would equal the pc of the
  941.      start of a function is a frameless function (i.e.
  942.      no prologue) where we branch back to the start
  943.      of the function.  In that case, SKIP_PROLOGUE won't
  944.      find one, and we'll clear caller_pc_valid a few lines
  945.      down.  */
  946.       caller_pc_valid = 1;
  947.       caller_pc = SAVED_PC_AFTER_CALL (fr);
  948.       callee_func_start = func_start;
  949.       SKIP_PROLOGUE (func_start);
  950.       callee_prologue_end = func_start;
  951.     }
  952.   if (caller_pc_valid)
  953.     {
  954.       if (fi->pc < callee_func_start
  955.       || fi->pc >= callee_prologue_end)
  956.     caller_pc_valid = 0;
  957.     }
  958.       
  959.   if (contained_in (block_for_pc (caller_pc_valid
  960.                   ? caller_pc
  961.                   : fi->pc),
  962.             valid_block))
  963.     {
  964.       return fr;
  965.     }
  966.   fr = get_prev_frame (fr);
  967.       
  968.   /* If any active frame is in the exp_valid_block, then it's
  969.      OK.  Note that this might not be the same invocation of
  970.      the exp_valid_block that we were watching a little while
  971.      ago, or the same one as when the watchpoint was set (e.g.
  972.      we are watching a local variable in a recursive function.
  973.      When we return from a recursive invocation, then we are
  974.      suddenly watching a different instance of the variable).
  975.  
  976.      At least for now I am going to consider this a feature.  */
  977.   for (; fr != NULL; fr = get_prev_frame (fr))
  978.     {
  979.       fi = get_frame_info (fr);
  980.       if (contained_in (block_for_pc (fi->pc),
  981.             valid_block))
  982.     {
  983.       return fr;
  984.     }
  985.     }
  986.   return NULL;
  987. }
  988.  
  989. /* Possible return values for watchpoint_check (this can't be an enum
  990.    because of check_errors).  */
  991. /* The watchpoint has been disabled.  */
  992. #define WP_DISABLED 1
  993. /* The value has changed.  */
  994. #define WP_VALUE_CHANGED 2
  995. /* The value has not changed.  */
  996. #define WP_VALUE_NOT_CHANGED 3
  997.  
  998. /* Check watchpoint condition.  */
  999. static int
  1000. watchpoint_check (p)
  1001.      char *p;
  1002. {
  1003.   bpstat bs = (bpstat) p;
  1004.   FRAME fr;
  1005.  
  1006.   int within_current_scope;
  1007.   if (bs->breakpoint_at->exp_valid_block == NULL)
  1008.     within_current_scope = 1;
  1009.   else
  1010.     {
  1011.       fr = within_scope (bs->breakpoint_at->exp_valid_block);
  1012.       within_current_scope = fr != NULL;
  1013.       if (within_current_scope)
  1014.     /* If we end up stopping, the current frame will get selected
  1015.        in normal_stop.  So this call to select_frame won't affect
  1016.        the user.  */
  1017.     select_frame (fr, -1);
  1018.     }
  1019.       
  1020.   if (within_current_scope)
  1021.     {
  1022.       /* We use value_{,free_to_}mark because it could be a
  1023.          *long* time before we return to the command level and
  1024.      call free_all_values.  We can't call free_all_values because
  1025.      we might be in the middle of evaluating a function call.  */
  1026.  
  1027.       value mark = value_mark ();
  1028.       value new_val = evaluate_expression (bs->breakpoint_at->exp);
  1029.       if (!value_equal (bs->breakpoint_at->val, new_val))
  1030.     {
  1031.       release_value (new_val);
  1032.       value_free_to_mark (mark);
  1033.       bs->old_val = bs->breakpoint_at->val;
  1034.       bs->breakpoint_at->val = new_val;
  1035.       /* We will stop here */
  1036.       return WP_VALUE_CHANGED;
  1037.     }
  1038.       else
  1039.     {
  1040.       /* Nothing changed, don't do anything.  */
  1041.       value_free_to_mark (mark);
  1042.       /* We won't stop here */
  1043.       return WP_VALUE_NOT_CHANGED;
  1044.     }
  1045.     }
  1046.   else
  1047.     {
  1048.       /* This seems like the only logical thing to do because
  1049.      if we temporarily ignored the watchpoint, then when
  1050.      we reenter the block in which it is valid it contains
  1051.      garbage (in the case of a function, it may have two
  1052.      garbage values, one before and one after the prologue).
  1053.      So we can't even detect the first assignment to it and
  1054.      watch after that (since the garbage may or may not equal
  1055.      the first value assigned).  */
  1056.       bs->breakpoint_at->enable = disabled;
  1057.       printf_filtered ("\
  1058. Watchpoint %d disabled because the program has left the block in\n\
  1059. which its expression is valid.\n", bs->breakpoint_at->number);
  1060.       return WP_DISABLED;
  1061.     }
  1062. }
  1063.  
  1064. /* This is used when everything which needs to be printed has
  1065.    already been printed.  But we still want to print the frame.  */
  1066. static int
  1067. print_it_done (bs)
  1068.      bpstat bs;
  1069. {
  1070.   return 0;
  1071. }
  1072.  
  1073. /* This is used when nothing should be printed for this bpstat entry.  */
  1074.  
  1075. static int
  1076. print_it_noop (bs)
  1077.      bpstat bs;
  1078. {
  1079.   return -1;
  1080. }
  1081.  
  1082. /* Get a bpstat associated with having just stopped at address *PC
  1083.    and frame address FRAME_ADDRESS.  Update *PC to point at the
  1084.    breakpoint (if we hit a breakpoint).  NOT_A_BREAKPOINT is nonzero
  1085.    if this is known to not be a real breakpoint (it could still be a
  1086.    watchpoint, though).  */
  1087.  
  1088. /* Determine whether we stopped at a breakpoint, etc, or whether we
  1089.    don't understand this stop.  Result is a chain of bpstat's such that:
  1090.  
  1091.     if we don't understand the stop, the result is a null pointer.
  1092.  
  1093.     if we understand why we stopped, the result is not null.
  1094.  
  1095.     Each element of the chain refers to a particular breakpoint or
  1096.     watchpoint at which we have stopped.  (We may have stopped for
  1097.     several reasons concurrently.)
  1098.  
  1099.     Each element of the chain has valid next, breakpoint_at,
  1100.     commands, FIXME??? fields.
  1101.  
  1102.  */
  1103.  
  1104. bpstat
  1105. bpstat_stop_status (pc, frame_address, not_a_breakpoint)
  1106.      CORE_ADDR *pc;
  1107.      FRAME_ADDR frame_address;
  1108.      int not_a_breakpoint;
  1109. {
  1110.   register struct breakpoint *b;
  1111.   CORE_ADDR bp_addr;
  1112. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1113.   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
  1114.   int real_breakpoint = 0;
  1115. #endif
  1116.   /* Root of the chain of bpstat's */
  1117.   struct bpstat root_bs[1];
  1118.   /* Pointer to the last thing in the chain currently.  */
  1119.   bpstat bs = root_bs;
  1120.  
  1121.   /* Get the address where the breakpoint would have been.  */
  1122.   bp_addr = *pc - DECR_PC_AFTER_BREAK;
  1123.  
  1124.   ALL_BREAKPOINTS (b)
  1125.     {
  1126.       if (b->enable == disabled)
  1127.     continue;
  1128.  
  1129.       if (b->type != bp_watchpoint && b->address != bp_addr)
  1130.     continue;
  1131.  
  1132.       if (b->type != bp_watchpoint && not_a_breakpoint)
  1133.     continue;
  1134.  
  1135.       /* Come here if it's a watchpoint, or if the break address matches */
  1136.  
  1137.       bs = bpstat_alloc (b, bs);    /* Alloc a bpstat to explain stop */
  1138.  
  1139.       bs->stop = 1;
  1140.       bs->print = 1;
  1141.  
  1142.       if (b->type == bp_watchpoint)
  1143.     {
  1144.       static char message1[] =
  1145.         "Error evaluating expression for watchpoint %d\n";
  1146.       char message[sizeof (message1) + 30 /* slop */];
  1147.       sprintf (message, message1, b->number);
  1148.       switch (catch_errors (watchpoint_check, (char *) bs, message,
  1149.                 RETURN_MASK_ALL))
  1150.         {
  1151.         case WP_DISABLED:
  1152.           /* We've already printed what needs to be printed.  */
  1153.           bs->print_it = print_it_done;
  1154.           /* Stop.  */
  1155.           break;
  1156.         case WP_VALUE_CHANGED:
  1157.           /* Stop.  */
  1158.           break;
  1159.         case WP_VALUE_NOT_CHANGED:
  1160.           /* Don't stop.  */
  1161.           bs->print_it = print_it_noop;
  1162.           bs->stop = 0;
  1163.           continue;
  1164.         default:
  1165.           /* Can't happen.  */
  1166.           /* FALLTHROUGH */
  1167.         case 0:
  1168.           /* Error from catch_errors.  */
  1169.           b->enable = disabled;
  1170.           printf_filtered ("Watchpoint %d disabled.\n", b->number);
  1171.           /* We've already printed what needs to be printed.  */
  1172.           bs->print_it = print_it_done;
  1173.           /* Stop.  */
  1174.           break;
  1175.         }
  1176.     }
  1177. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1178.       else
  1179.     real_breakpoint = 1;
  1180. #endif
  1181.  
  1182.       if (b->frame && b->frame != frame_address)
  1183.     bs->stop = 0;
  1184.       else
  1185.     {
  1186.       int value_is_zero = 0;
  1187.  
  1188.       if (b->cond)
  1189.         {
  1190.           /* Need to select the frame, with all that implies
  1191.          so that the conditions will have the right context.  */
  1192.           select_frame (get_current_frame (), 0);
  1193.           value_is_zero
  1194.         = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
  1195.                 "Error in testing breakpoint condition:\n",
  1196.                 RETURN_MASK_ALL);
  1197.                 /* FIXME-someday, should give breakpoint # */
  1198.           free_all_values ();
  1199.         }
  1200.       if (b->cond && value_is_zero)
  1201.         {
  1202.           bs->stop = 0;
  1203.         }
  1204.       else if (b->ignore_count > 0)
  1205.         {
  1206.           b->ignore_count--;
  1207.           bs->stop = 0;
  1208.         }
  1209.       else
  1210.         {
  1211.           /* We will stop here */
  1212.           if (b->disposition == disable)
  1213.         b->enable = disabled;
  1214.           bs->commands = b->commands;
  1215.           if (b->silent)
  1216.         bs->print = 0;
  1217.           if (bs->commands && STREQ ("silent", bs->commands->line))
  1218.         {
  1219.           bs->commands = bs->commands->next;
  1220.           bs->print = 0;
  1221.         }
  1222.         }
  1223.     }
  1224.       /* Print nothing for this entry if we dont stop or if we dont print.  */
  1225.       if (bs->stop == 0 || bs->print == 0)
  1226.     bs->print_it = print_it_noop;
  1227.     }
  1228.  
  1229.   bs->next = NULL;        /* Terminate the chain */
  1230.   bs = root_bs->next;        /* Re-grab the head of the chain */
  1231. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  1232.   if (bs)
  1233.     {
  1234.       if (real_breakpoint)
  1235.     {
  1236.       *pc = bp_addr;
  1237. #if defined (SHIFT_INST_REGS)
  1238.       SHIFT_INST_REGS();
  1239. #else /* No SHIFT_INST_REGS.  */
  1240.       write_pc (bp_addr);
  1241. #endif /* No SHIFT_INST_REGS.  */
  1242.     }
  1243.     }
  1244. #endif /* DECR_PC_AFTER_BREAK != 0.  */
  1245.   return bs;
  1246. }
  1247.  
  1248. /* Tell what to do about this bpstat.  */
  1249. struct bpstat_what
  1250. bpstat_what (bs)
  1251.      bpstat bs;
  1252. {
  1253.   /* Classify each bpstat as one of the following.  */
  1254.   enum class {
  1255.     /* This bpstat element has no effect on the main_action.  */
  1256.     no_effect = 0,
  1257.  
  1258.     /* There was a watchpoint, stop but don't print.  */
  1259.     wp_silent,
  1260.  
  1261.     /* There was a watchpoint, stop and print.  */
  1262.     wp_noisy,
  1263.  
  1264.     /* There was a breakpoint but we're not stopping.  */
  1265.     bp_nostop,
  1266.  
  1267.     /* There was a breakpoint, stop but don't print.  */
  1268.     bp_silent,
  1269.  
  1270.     /* There was a breakpoint, stop and print.  */
  1271.     bp_noisy,
  1272.  
  1273.     /* We hit the longjmp breakpoint.  */
  1274.     long_jump,
  1275.  
  1276.     /* We hit the longjmp_resume breakpoint.  */
  1277.     long_resume,
  1278.  
  1279.     /* This is just used to count how many enums there are.  */
  1280.     class_last
  1281.     };
  1282.  
  1283.   /* Here is the table which drives this routine.  So that we can
  1284.      format it pretty, we define some abbreviations for the
  1285.      enum bpstat_what codes.  */
  1286. #define keep_c BPSTAT_WHAT_KEEP_CHECKING
  1287. #define stop_s BPSTAT_WHAT_STOP_SILENT
  1288. #define stop_n BPSTAT_WHAT_STOP_NOISY
  1289. #define single BPSTAT_WHAT_SINGLE
  1290. #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
  1291. #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
  1292. #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
  1293. /* "Can't happen."  Might want to print an error message.
  1294.    abort() is not out of the question, but chances are GDB is just
  1295.    a bit confused, not unusable.  */
  1296. #define err BPSTAT_WHAT_STOP_NOISY
  1297.  
  1298.   /* Given an old action and a class, come up with a new action.  */
  1299.   /* One interesting property of this table is that wp_silent is the same
  1300.      as bp_silent and wp_noisy is the same as bp_noisy.  That is because
  1301.      after stopping, the check for whether to step over a breakpoint
  1302.      (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
  1303.      reference to how we stopped.  We retain separate wp_silent and bp_silent
  1304.      codes in case we want to change that someday.  */
  1305.   static const enum bpstat_what_main_action
  1306.     table[(int)class_last][(int)BPSTAT_WHAT_LAST] =
  1307.       {
  1308.     /*                              old action */
  1309.     /*       keep_c  stop_s  stop_n  single  setlr   clrlr   clrlrs */
  1310.  
  1311. /*no_effect*/    {keep_c, stop_s, stop_n, single, setlr , clrlr , clrlrs},
  1312. /*wp_silent*/    {stop_s, stop_s, stop_n, stop_s, stop_s, stop_s, stop_s},
  1313. /*wp_noisy*/    {stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, stop_n},
  1314. /*bp_nostop*/    {single, stop_s, stop_n, single, setlr , clrlrs, clrlrs},
  1315. /*bp_silent*/    {stop_s, stop_s, stop_n, stop_s, stop_s, stop_s, stop_s},
  1316. /*bp_noisy*/    {stop_n, stop_n, stop_n, stop_n, stop_n, stop_n, stop_n},
  1317. /*long_jump*/    {setlr , stop_s, stop_n, setlr , err   , err   , err   },
  1318. /*long_resume*/    {clrlr , stop_s, stop_n, clrlrs, err   , err   , err   }
  1319.           };
  1320. #undef keep_c
  1321. #undef stop_s
  1322. #undef stop_n
  1323. #undef single
  1324. #undef setlr
  1325. #undef clrlr
  1326. #undef clrlrs
  1327. #undef err
  1328.   enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
  1329.   struct bpstat_what retval;
  1330.  
  1331.   retval.call_dummy = 0;
  1332.   retval.step_resume = 0;
  1333.   for (; bs != NULL; bs = bs->next)
  1334.     {
  1335.       enum class bs_class = no_effect;
  1336.       if (bs->breakpoint_at == NULL)
  1337.     /* I suspect this can happen if it was a momentary breakpoint
  1338.        which has since been deleted.  */
  1339.     continue;
  1340.       switch (bs->breakpoint_at->type)
  1341.     {
  1342.     case bp_breakpoint:
  1343.     case bp_until:
  1344.     case bp_finish:
  1345.       if (bs->stop)
  1346.         {
  1347.           if (bs->print)
  1348.         bs_class = bp_noisy;
  1349.           else
  1350.         bs_class = bp_silent;
  1351.         }
  1352.       else
  1353.         bs_class = bp_nostop;
  1354.       break;
  1355.     case bp_watchpoint:
  1356.       if (bs->stop)
  1357.         {
  1358.           if (bs->print)
  1359.         bs_class = wp_noisy;
  1360.           else
  1361.         bs_class = wp_silent;
  1362.         }
  1363.       else
  1364.         /* There was a watchpoint, but we're not stopping.  This requires
  1365.            no further action.  */
  1366.         bs_class = no_effect;
  1367.       break;
  1368.     case bp_longjmp:
  1369.       bs_class = long_jump;
  1370.       break;
  1371.     case bp_longjmp_resume:
  1372.       bs_class = long_resume;
  1373.       break;
  1374.     case bp_step_resume:
  1375. #if 0
  1376.       /* Need to temporarily disable this until we can fix the bug
  1377.          with nexting over a breakpoint with ->stop clear causing
  1378.          an infinite loop.  For now, treat the breakpoint as having
  1379.          been hit even if the frame is wrong.  */
  1380.       if (bs->stop)
  1381.         {
  1382. #endif
  1383.           retval.step_resume = 1;
  1384.           /* We don't handle this via the main_action.  */
  1385.           bs_class = no_effect;
  1386. #if 0
  1387.         }
  1388.       else
  1389.         /* It is for the wrong frame.  */
  1390.         bs_class = bp_nostop;
  1391. #endif
  1392.       break;
  1393.     case bp_call_dummy:
  1394.       /* Make sure the action is stop (silent or noisy), so infrun.c
  1395.          pops the dummy frame.  */
  1396.       bs_class = bp_silent;
  1397.       retval.call_dummy = 1;
  1398.       break;
  1399.     }
  1400.       current_action = table[(int)bs_class][(int)current_action];
  1401.     }
  1402.   retval.main_action = current_action;
  1403.   return retval;
  1404. }
  1405.  
  1406. /* Nonzero if we should step constantly (e.g. watchpoints on machines
  1407.    without hardware support).  This isn't related to a specific bpstat,
  1408.    just to things like whether watchpoints are set.  */
  1409.  
  1410. int 
  1411. bpstat_should_step ()
  1412. {
  1413.   struct breakpoint *b;
  1414.   ALL_BREAKPOINTS (b)
  1415.     if (b->enable == enabled && b->type == bp_watchpoint)
  1416.       return 1;
  1417.   return 0;
  1418. }
  1419.  
  1420. /* Print information on breakpoint number BNUM, or -1 if all.
  1421.    If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
  1422.    is nonzero, process only watchpoints.  */
  1423.  
  1424. static void
  1425. breakpoint_1 (bnum, allflag)
  1426.      int bnum;
  1427.      int allflag;
  1428. {
  1429.   register struct breakpoint *b;
  1430.   register struct command_line *l;
  1431.   register struct symbol *sym;
  1432.   CORE_ADDR last_addr = (CORE_ADDR)-1;
  1433.   int found_a_breakpoint = 0;
  1434.   static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint",
  1435.                   "longjmp", "longjmp resume", "step resume",
  1436.                   "call dummy" };
  1437.   static char *bpdisps[] = {"del", "dis", "keep"};
  1438.   static char bpenables[] = "ny";
  1439.   char wrap_indent[80];
  1440.  
  1441.   ALL_BREAKPOINTS (b)
  1442.     if (bnum == -1
  1443.     || bnum == b->number)
  1444.       {
  1445. /*  We only print out user settable breakpoints unless the allflag is set. */
  1446.     if (!allflag
  1447.         && b->type != bp_breakpoint
  1448.         && b->type != bp_watchpoint)
  1449.       continue;
  1450.  
  1451.     if (!found_a_breakpoint++)
  1452.       printf_filtered ("Num Type           Disp Enb %sWhat\n",
  1453.                addressprint ? "Address    " : "");
  1454.  
  1455.     printf_filtered ("%-3d %-14s %-4s %-3c ",
  1456.              b->number,
  1457.              bptypes[(int)b->type],
  1458.              bpdisps[(int)b->disposition],
  1459.              bpenables[(int)b->enable]);
  1460.     strcpy (wrap_indent, "                           ");
  1461.     if (addressprint)
  1462.       strcat (wrap_indent, "           ");
  1463.     switch (b->type)
  1464.       {
  1465.       case bp_watchpoint:
  1466.         print_expression (b->exp, gdb_stdout);
  1467.         break;
  1468.  
  1469.       case bp_breakpoint:
  1470.       case bp_until:
  1471.       case bp_finish:
  1472.       case bp_longjmp:
  1473.       case bp_longjmp_resume:
  1474.       case bp_step_resume:
  1475.       case bp_call_dummy:
  1476.         if (addressprint)
  1477.           printf_filtered ("%s ", local_hex_string_custom ((unsigned long) b->address, "08l"));
  1478.  
  1479.         last_addr = b->address;
  1480.         if (b->source_file)
  1481.           {
  1482.         sym = find_pc_function (b->address);
  1483.         if (sym)
  1484.           {
  1485.             fputs_filtered ("in ", gdb_stdout);
  1486.             fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
  1487.             wrap_here (wrap_indent);
  1488.             fputs_filtered (" at ", gdb_stdout);
  1489.           }
  1490.         fputs_filtered (b->source_file, gdb_stdout);
  1491.         printf_filtered (":%d", b->line_number);
  1492.           }
  1493.         else
  1494.           print_address_symbolic (b->address, gdb_stdout, demangle, " ");
  1495.         break;
  1496.       }
  1497.  
  1498.     printf_filtered ("\n");
  1499.  
  1500.     if (b->frame)
  1501.       printf_filtered ("\tstop only in stack frame at %s\n",
  1502.                local_hex_string((unsigned long) b->frame));
  1503.     if (b->cond)
  1504.       {
  1505.         printf_filtered ("\tstop only if ");
  1506.         print_expression (b->cond, gdb_stdout);
  1507.         printf_filtered ("\n");
  1508.       }
  1509.     if (b->ignore_count)
  1510.       printf_filtered ("\tignore next %d hits\n", b->ignore_count);
  1511.     if ((l = b->commands))
  1512.       while (l)
  1513.         {
  1514.           fputs_filtered ("\t", gdb_stdout);
  1515.           fputs_filtered (l->line, gdb_stdout);
  1516.           fputs_filtered ("\n", gdb_stdout);
  1517.           l = l->next;
  1518.         }
  1519.       }
  1520.  
  1521.   if (!found_a_breakpoint)
  1522.     {
  1523.       if (bnum == -1)
  1524.         printf_filtered ("No breakpoints or watchpoints.\n");
  1525.       else
  1526.         printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum);
  1527.     }
  1528.   else
  1529.     /* Compare against (CORE_ADDR)-1 in case some compiler decides
  1530.        that a comparison of an unsigned with -1 is always false.  */
  1531.     if (last_addr != (CORE_ADDR)-1)
  1532.       set_next_address (last_addr);
  1533. }
  1534.  
  1535. /* ARGSUSED */
  1536. static void
  1537. breakpoints_info (bnum_exp, from_tty)
  1538.      char *bnum_exp;
  1539.      int from_tty;
  1540. {
  1541.   int bnum = -1;
  1542.  
  1543.   if (bnum_exp)
  1544.     bnum = parse_and_eval_address (bnum_exp);
  1545.  
  1546.   breakpoint_1 (bnum, 0);
  1547. }
  1548.  
  1549. #if MAINTENANCE_CMDS
  1550.  
  1551. /* ARGSUSED */
  1552. static void
  1553. maintenance_info_breakpoints (bnum_exp, from_tty)
  1554.      char *bnum_exp;
  1555.      int from_tty;
  1556. {
  1557.   int bnum = -1;
  1558.  
  1559.   if (bnum_exp)
  1560.     bnum = parse_and_eval_address (bnum_exp);
  1561.  
  1562.   breakpoint_1 (bnum, 1);
  1563. }
  1564.  
  1565. #endif
  1566.  
  1567. /* Print a message describing any breakpoints set at PC.  */
  1568.  
  1569. static void
  1570. describe_other_breakpoints (pc)
  1571.      register CORE_ADDR pc;
  1572. {
  1573.   register int others = 0;
  1574.   register struct breakpoint *b;
  1575.  
  1576.   ALL_BREAKPOINTS (b)
  1577.     if (b->address == pc)
  1578.       others++;
  1579.   if (others > 0)
  1580.     {
  1581.       printf_unfiltered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
  1582.       ALL_BREAKPOINTS (b)
  1583.     if (b->address == pc)
  1584.       {
  1585.         others--;
  1586.         printf_unfiltered ("%d%s%s ",
  1587.             b->number,
  1588.             (b->enable == disabled) ? " (disabled)" : "",
  1589.             (others > 1) ? "," : ((others == 1) ? " and" : ""));
  1590.       }
  1591.       printf_unfiltered ("also set at pc %s.\n", local_hex_string((unsigned long) pc));
  1592.     }
  1593. }
  1594.  
  1595. /* Set the default place to put a breakpoint
  1596.    for the `break' command with no arguments.  */
  1597.  
  1598. void
  1599. set_default_breakpoint (valid, addr, symtab, line)
  1600.      int valid;
  1601.      CORE_ADDR addr;
  1602.      struct symtab *symtab;
  1603.      int line;
  1604. {
  1605.   default_breakpoint_valid = valid;
  1606.   default_breakpoint_address = addr;
  1607.   default_breakpoint_symtab = symtab;
  1608.   default_breakpoint_line = line;
  1609. }
  1610.  
  1611. /* Rescan breakpoints at address ADDRESS,
  1612.    marking the first one as "first" and any others as "duplicates".
  1613.    This is so that the bpt instruction is only inserted once.  */
  1614.  
  1615. static void
  1616. check_duplicates (address)
  1617.      CORE_ADDR address;
  1618. {
  1619.   register struct breakpoint *b;
  1620.   register int count = 0;
  1621.  
  1622.   if (address == 0)        /* Watchpoints are uninteresting */
  1623.     return;
  1624.  
  1625.   ALL_BREAKPOINTS (b)
  1626.     if (b->enable != disabled && b->address == address)
  1627.       {
  1628.     count++;
  1629.     b->duplicate = count > 1;
  1630.       }
  1631. }
  1632.  
  1633. /* Low level routine to set a breakpoint.
  1634.    Takes as args the three things that every breakpoint must have.
  1635.    Returns the breakpoint object so caller can set other things.
  1636.    Does not set the breakpoint number!
  1637.    Does not print anything.
  1638.  
  1639.    ==> This routine should not be called if there is a chance of later
  1640.    error(); otherwise it leaves a bogus breakpoint on the chain.  Validate
  1641.    your arguments BEFORE calling this routine!  */
  1642.  
  1643. static struct breakpoint *
  1644. set_raw_breakpoint (sal)
  1645.      struct symtab_and_line sal;
  1646. {
  1647.   register struct breakpoint *b, *b1;
  1648.  
  1649.   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
  1650.   memset (b, 0, sizeof (*b));
  1651.   b->address = sal.pc;
  1652.   if (sal.symtab == NULL)
  1653.     b->source_file = NULL;
  1654.   else
  1655.     b->source_file = savestring (sal.symtab->filename,
  1656.                  strlen (sal.symtab->filename));
  1657.   b->thread = -1;
  1658.   b->line_number = sal.line;
  1659.   b->enable = enabled;
  1660.   b->next = 0;
  1661.   b->silent = 0;
  1662.   b->ignore_count = 0;
  1663.   b->commands = NULL;
  1664.   b->frame = 0;
  1665.  
  1666.   /* Add this breakpoint to the end of the chain
  1667.      so that a list of breakpoints will come out in order
  1668.      of increasing numbers.  */
  1669.  
  1670.   b1 = breakpoint_chain;
  1671.   if (b1 == 0)
  1672.     breakpoint_chain = b;
  1673.   else
  1674.     {
  1675.       while (b1->next)
  1676.     b1 = b1->next;
  1677.       b1->next = b;
  1678.     }
  1679.  
  1680.   check_duplicates (sal.pc);
  1681.  
  1682.   return b;
  1683. }
  1684.  
  1685. static void
  1686. create_longjmp_breakpoint(func_name)
  1687.      char *func_name;
  1688. {
  1689.   struct symtab_and_line sal;
  1690.   struct breakpoint *b;
  1691.   static int internal_breakpoint_number = -1;
  1692.  
  1693.   if (func_name != NULL)
  1694.     {
  1695.       struct minimal_symbol *m;
  1696.  
  1697.       m = lookup_minimal_symbol(func_name, (struct objfile *)NULL);
  1698.       if (m)
  1699.     sal.pc = SYMBOL_VALUE_ADDRESS (m);
  1700.       else
  1701.     return;
  1702.     }
  1703.   else
  1704.     sal.pc = 0;
  1705.  
  1706.   sal.symtab = NULL;
  1707.   sal.line = 0;
  1708.  
  1709.   b = set_raw_breakpoint(sal);
  1710.   if (!b) return;
  1711.  
  1712.   b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume;
  1713.   b->disposition = donttouch;
  1714.   b->enable = disabled;
  1715.   b->silent = 1;
  1716.   if (func_name)
  1717.     b->addr_string = strsave(func_name);
  1718.   b->number = internal_breakpoint_number--;
  1719. }
  1720.  
  1721. /* Call this routine when stepping and nexting to enable a breakpoint if we do
  1722.    a longjmp().  When we hit that breakpoint, call
  1723.    set_longjmp_resume_breakpoint() to figure out where we are going. */
  1724.  
  1725. void
  1726. enable_longjmp_breakpoint()
  1727. {
  1728.   register struct breakpoint *b;
  1729.  
  1730.   ALL_BREAKPOINTS (b)
  1731.     if (b->type == bp_longjmp)
  1732.       {
  1733.     b->enable = enabled;
  1734.     check_duplicates (b->address);
  1735.       }
  1736. }
  1737.  
  1738. void
  1739. disable_longjmp_breakpoint()
  1740. {
  1741.   register struct breakpoint *b;
  1742.  
  1743.   ALL_BREAKPOINTS (b)
  1744.     if (   b->type == bp_longjmp
  1745.     || b->type == bp_longjmp_resume)
  1746.       {
  1747.     b->enable = disabled;
  1748.     check_duplicates (b->address);
  1749.       }
  1750. }
  1751.  
  1752. /* Call this after hitting the longjmp() breakpoint.  Use this to set a new
  1753.    breakpoint at the target of the jmp_buf.
  1754.  
  1755.    FIXME - This ought to be done by setting a temporary breakpoint that gets
  1756.    deleted automatically...
  1757. */
  1758.  
  1759. void
  1760. set_longjmp_resume_breakpoint(pc, frame)
  1761.      CORE_ADDR pc;
  1762.      FRAME frame;
  1763. {
  1764.   register struct breakpoint *b;
  1765.  
  1766.   ALL_BREAKPOINTS (b)
  1767.     if (b->type == bp_longjmp_resume)
  1768.       {
  1769.     b->address = pc;
  1770.     b->enable = enabled;
  1771.     if (frame != NULL)
  1772.       b->frame = FRAME_FP(frame);
  1773.     else
  1774.       b->frame = 0;
  1775.     check_duplicates (b->address);
  1776.     return;
  1777.       }
  1778. }
  1779.  
  1780. /* Set a breakpoint that will evaporate an end of command
  1781.    at address specified by SAL.
  1782.    Restrict it to frame FRAME if FRAME is nonzero.  */
  1783.  
  1784. struct breakpoint *
  1785. set_momentary_breakpoint (sal, frame, type)
  1786.      struct symtab_and_line sal;
  1787.      FRAME frame;
  1788.      enum bptype type;
  1789. {
  1790.   register struct breakpoint *b;
  1791.   b = set_raw_breakpoint (sal);
  1792.   b->type = type;
  1793.   b->enable = enabled;
  1794.   b->disposition = donttouch;
  1795.   b->frame = (frame ? FRAME_FP (frame) : 0);
  1796.   return b;
  1797. }
  1798.  
  1799. #if 0
  1800. void
  1801. clear_momentary_breakpoints ()
  1802. {
  1803.   register struct breakpoint *b;
  1804.   ALL_BREAKPOINTS (b)
  1805.     if (b->disposition == delete)
  1806.       {
  1807.     delete_breakpoint (b);
  1808.     break;
  1809.       }
  1810. }
  1811. #endif
  1812.  
  1813. /* Tell the user we have just set a breakpoint B.  */
  1814. static void
  1815. mention (b)
  1816.      struct breakpoint *b;
  1817. {
  1818.   switch (b->type)
  1819.     {
  1820.     case bp_watchpoint:
  1821.       printf_filtered ("Watchpoint %d: ", b->number);
  1822.       print_expression (b->exp, gdb_stdout);
  1823.       break;
  1824.     case bp_breakpoint:
  1825.       printf_filtered ("Breakpoint %d at %s", b->number,
  1826.                local_hex_string((unsigned long) b->address));
  1827.       if (b->source_file)
  1828.     printf_filtered (": file %s, line %d.",
  1829.              b->source_file, b->line_number);
  1830.       break;
  1831.     case bp_until:
  1832.     case bp_finish:
  1833.     case bp_longjmp:
  1834.     case bp_longjmp_resume:
  1835.     case bp_step_resume:
  1836.     case bp_call_dummy:
  1837.       break;
  1838.     }
  1839.   printf_filtered ("\n");
  1840. }
  1841.  
  1842. #if 0
  1843. /* Nobody calls this currently. */
  1844. /* Set a breakpoint from a symtab and line.
  1845.    If TEMPFLAG is nonzero, it is a temporary breakpoint.
  1846.    ADDR_STRING is a malloc'd string holding the name of where we are
  1847.    setting the breakpoint.  This is used later to re-set it after the
  1848.    program is relinked and symbols are reloaded.
  1849.    Print the same confirmation messages that the breakpoint command prints.  */
  1850.  
  1851. void
  1852. set_breakpoint (s, line, tempflag, addr_string)
  1853.      struct symtab *s;
  1854.      int line;
  1855.      int tempflag;
  1856.      char *addr_string;
  1857. {
  1858.   register struct breakpoint *b;
  1859.   struct symtab_and_line sal;
  1860.   
  1861.   sal.symtab = s;
  1862.   sal.line = line;
  1863.   sal.pc = 0;
  1864.   resolve_sal_pc (&sal);            /* Might error out */
  1865.   describe_other_breakpoints (sal.pc);
  1866.  
  1867.   b = set_raw_breakpoint (sal);
  1868.   set_breakpoint_count (breakpoint_count + 1);
  1869.   b->number = breakpoint_count;
  1870.   b->type = bp_breakpoint;
  1871.   b->cond = 0;
  1872.   b->addr_string = addr_string;
  1873.   b->enable = enabled;
  1874.   b->disposition = tempflag ? delete : donttouch;
  1875.  
  1876.   mention (b);
  1877. }
  1878. #endif /* 0 */
  1879.  
  1880. /* Set a breakpoint according to ARG (function, linenum or *address)
  1881.    and make it temporary if TEMPFLAG is nonzero. */
  1882.  
  1883. static void
  1884. break_command_1 (arg, tempflag, from_tty)
  1885.      char *arg;
  1886.      int tempflag, from_tty;
  1887. {
  1888.   struct symtabs_and_lines sals;
  1889.   struct symtab_and_line sal;
  1890.   register struct expression *cond = 0;
  1891.   register struct breakpoint *b;
  1892.  
  1893.   /* Pointers in arg to the start, and one past the end, of the condition.  */
  1894.   char *cond_start = NULL;
  1895.   char *cond_end = NULL;
  1896.   /* Pointers in arg to the start, and one past the end,
  1897.      of the address part.  */
  1898.   char *addr_start = NULL;
  1899.   char *addr_end = NULL;
  1900.   struct cleanup *old_chain;
  1901.   struct cleanup *canonical_strings_chain = NULL;
  1902.   char **canonical = (char **)NULL;
  1903.   int i;
  1904.   int thread;
  1905.  
  1906.   sals.sals = NULL;
  1907.   sals.nelts = 0;
  1908.  
  1909.   sal.line = sal.pc = sal.end = 0;
  1910.   sal.symtab = 0;
  1911.  
  1912.   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
  1913.  
  1914.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  1915.            && (arg[2] == ' ' || arg[2] == '\t')))
  1916.     {
  1917.       if (default_breakpoint_valid)
  1918.     {
  1919.       sals.sals = (struct symtab_and_line *) 
  1920.         xmalloc (sizeof (struct symtab_and_line));
  1921.       sal.pc = default_breakpoint_address;
  1922.       sal.line = default_breakpoint_line;
  1923.       sal.symtab = default_breakpoint_symtab;
  1924.       sals.sals[0] = sal;
  1925.       sals.nelts = 1;
  1926.     }
  1927.       else
  1928.     error ("No default breakpoint address now.");
  1929.     }
  1930.   else
  1931.     {
  1932.       addr_start = arg;
  1933.  
  1934.       /* Force almost all breakpoints to be in terms of the
  1935.      current_source_symtab (which is decode_line_1's default).  This
  1936.      should produce the results we want almost all of the time while
  1937.      leaving default_breakpoint_* alone.  */
  1938.       if (default_breakpoint_valid
  1939.       && (!current_source_symtab
  1940.           || (arg && (*arg == '+' || *arg == '-'))))
  1941.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  1942.                   default_breakpoint_line, &canonical);
  1943.       else
  1944.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
  1945.  
  1946.       addr_end = arg;
  1947.     }
  1948.   
  1949.   if (! sals.nelts) 
  1950.     return;
  1951.  
  1952.   /* Make sure that all storage allocated in decode_line_1 gets freed in case
  1953.      the following `for' loop errors out.  */
  1954.   old_chain = make_cleanup (free, sals.sals);
  1955.   if (canonical != (char **)NULL)
  1956.     {
  1957.       make_cleanup (free, canonical);
  1958.       canonical_strings_chain = make_cleanup (null_cleanup, 0);
  1959.       for (i = 0; i < sals.nelts; i++)
  1960.     {
  1961.       if (canonical[i] != NULL)
  1962.         make_cleanup (free, canonical[i]);
  1963.     }
  1964.     }
  1965.  
  1966.   thread = -1;            /* No specific thread yet */
  1967.  
  1968.   /* Resolve all line numbers to PC's, and verify that conditions
  1969.      can be parsed, before setting any breakpoints.  */
  1970.   for (i = 0; i < sals.nelts; i++)
  1971.     {
  1972.       char *tok, *end_tok;
  1973.       int toklen;
  1974.  
  1975.       resolve_sal_pc (&sals.sals[i]);
  1976.       
  1977.       tok = arg;
  1978.  
  1979.       while (tok && *tok)
  1980.     {
  1981.       while (*tok == ' ' || *tok == '\t')
  1982.         tok++;
  1983.  
  1984.       end_tok = tok;
  1985.  
  1986.       while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
  1987.         end_tok++;
  1988.  
  1989.       toklen = end_tok - tok;
  1990.  
  1991.       if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
  1992.         {
  1993.           tok = cond_start = end_tok + 1;
  1994.           cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
  1995.           cond_end = tok;
  1996.         }
  1997.       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
  1998.         {
  1999.           char *tmptok;
  2000.  
  2001.           tok = end_tok + 1;
  2002.           tmptok = tok;
  2003.           thread = strtol (tok, &tok, 0);
  2004.           if (tok == tmptok)
  2005.         error ("Junk after thread keyword.");
  2006.           if (!valid_thread_id (thread))
  2007.         error ("Unknown thread %d\n", thread);
  2008.         }
  2009.       else
  2010.         error ("Junk at end of arguments.");
  2011.     }
  2012.     }
  2013.  
  2014.   /* Remove the canonical strings from the cleanup, they are needed below.  */
  2015.   if (canonical != (char **)NULL)
  2016.     discard_cleanups (canonical_strings_chain);
  2017.  
  2018.   /* Now set all the breakpoints.  */
  2019.   for (i = 0; i < sals.nelts; i++)
  2020.     {
  2021.       sal = sals.sals[i];
  2022.  
  2023.       if (from_tty)
  2024.     describe_other_breakpoints (sal.pc);
  2025.  
  2026.       b = set_raw_breakpoint (sal);
  2027.       set_breakpoint_count (breakpoint_count + 1);
  2028.       b->number = breakpoint_count;
  2029.       b->type = bp_breakpoint;
  2030.       b->cond = cond;
  2031.       b->thread = thread;
  2032.  
  2033.       /* If a canonical line spec is needed use that instead of the
  2034.      command string.  */
  2035.       if (canonical != (char **)NULL && canonical[i] != NULL)
  2036.     b->addr_string = canonical[i];
  2037.       else if (addr_start)
  2038.     b->addr_string = savestring (addr_start, addr_end - addr_start);
  2039.       if (cond_start)
  2040.     b->cond_string = savestring (cond_start, cond_end - cond_start);
  2041.                      
  2042.       b->enable = enabled;
  2043.       b->disposition = tempflag ? delete : donttouch;
  2044.  
  2045.       mention (b);
  2046.     }
  2047.  
  2048.   if (sals.nelts > 1)
  2049.     {
  2050.       printf_unfiltered ("Multiple breakpoints were set.\n");
  2051.       printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  2052.     }
  2053.   do_cleanups (old_chain);
  2054. }
  2055.  
  2056. /* Helper function for break_command_1 and disassemble_command.  */
  2057.  
  2058. void
  2059. resolve_sal_pc (sal)
  2060.      struct symtab_and_line *sal;
  2061. {
  2062.   CORE_ADDR pc;
  2063.  
  2064.   if (sal->pc == 0 && sal->symtab != 0)
  2065.     {
  2066.       pc = find_line_pc (sal->symtab, sal->line);
  2067.       if (pc == 0)
  2068.     error ("No line %d in file \"%s\".",
  2069.            sal->line, sal->symtab->filename);
  2070.       sal->pc = pc;
  2071.     }
  2072. }
  2073.  
  2074. void
  2075. break_command (arg, from_tty)
  2076.      char *arg;
  2077.      int from_tty;
  2078. {
  2079.   break_command_1 (arg, 0, from_tty);
  2080. }
  2081.  
  2082. static void
  2083. tbreak_command (arg, from_tty)
  2084.      char *arg;
  2085.      int from_tty;
  2086. {
  2087.   break_command_1 (arg, 1, from_tty);
  2088. }
  2089.  
  2090. /* ARGSUSED */
  2091. static void
  2092. watch_command (arg, from_tty)
  2093.      char *arg;
  2094.      int from_tty;
  2095. {
  2096.   struct breakpoint *b;
  2097.   struct symtab_and_line sal;
  2098.   struct expression *exp;
  2099.   struct block *exp_valid_block;
  2100.   struct value *val;
  2101.  
  2102.   sal.pc = 0;
  2103.   sal.symtab = NULL;
  2104.   sal.line = 0;
  2105.   
  2106.   /* Parse arguments.  */
  2107.   innermost_block = NULL;
  2108.   exp = parse_expression (arg);
  2109.   exp_valid_block = innermost_block;
  2110.   val = evaluate_expression (exp);
  2111.   release_value (val);
  2112.   if (VALUE_LAZY (val))
  2113.     value_fetch_lazy (val);
  2114.  
  2115.   /* Now set up the breakpoint.  */
  2116.   b = set_raw_breakpoint (sal);
  2117.   set_breakpoint_count (breakpoint_count + 1);
  2118.   b->number = breakpoint_count;
  2119.   b->type = bp_watchpoint;
  2120.   b->disposition = donttouch;
  2121.   b->exp = exp;
  2122.   b->exp_valid_block = exp_valid_block;
  2123.   b->val = val;
  2124.   b->cond = 0;
  2125.   b->cond_string = NULL;
  2126.   b->exp_string = savestring (arg, strlen (arg));
  2127.   mention (b);
  2128. }
  2129.  
  2130. /*
  2131.  * Helper routine for the until_command routine in infcmd.c.  Here
  2132.  * because it uses the mechanisms of breakpoints.
  2133.  */
  2134. /* ARGSUSED */
  2135. void
  2136. until_break_command (arg, from_tty)
  2137.      char *arg;
  2138.      int from_tty;
  2139. {
  2140.   struct symtabs_and_lines sals;
  2141.   struct symtab_and_line sal;
  2142.   FRAME prev_frame = get_prev_frame (selected_frame);
  2143.   struct breakpoint *breakpoint;
  2144.   struct cleanup *old_chain;
  2145.  
  2146.   clear_proceed_status ();
  2147.  
  2148.   /* Set a breakpoint where the user wants it and at return from
  2149.      this function */
  2150.   
  2151.   if (default_breakpoint_valid)
  2152.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  2153.               default_breakpoint_line, (char ***)NULL);
  2154.   else
  2155.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL);
  2156.   
  2157.   if (sals.nelts != 1)
  2158.     error ("Couldn't get information on specified line.");
  2159.   
  2160.   sal = sals.sals[0];
  2161.   free ((PTR)sals.sals);        /* malloc'd, so freed */
  2162.   
  2163.   if (*arg)
  2164.     error ("Junk at end of arguments.");
  2165.   
  2166.   resolve_sal_pc (&sal);
  2167.   
  2168.   breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until);
  2169.   
  2170.   old_chain = make_cleanup(delete_breakpoint, breakpoint);
  2171.  
  2172.   /* Keep within the current frame */
  2173.   
  2174.   if (prev_frame)
  2175.     {
  2176.       struct frame_info *fi;
  2177.       
  2178.       fi = get_frame_info (prev_frame);
  2179.       sal = find_pc_line (fi->pc, 0);
  2180.       sal.pc = fi->pc;
  2181.       breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until);
  2182.       make_cleanup(delete_breakpoint, breakpoint);
  2183.     }
  2184.   
  2185.   proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
  2186.   do_cleanups(old_chain);
  2187. }
  2188.  
  2189. #if 0
  2190. /* These aren't used; I don't konw what they were for.  */
  2191. /* Set a breakpoint at the catch clause for NAME.  */
  2192. static int
  2193. catch_breakpoint (name)
  2194.      char *name;
  2195. {
  2196. }
  2197.  
  2198. static int
  2199. disable_catch_breakpoint ()
  2200. {
  2201. }
  2202.  
  2203. static int
  2204. delete_catch_breakpoint ()
  2205. {
  2206. }
  2207.  
  2208. static int
  2209. enable_catch_breakpoint ()
  2210. {
  2211. }
  2212. #endif /* 0 */
  2213.  
  2214. struct sal_chain
  2215. {
  2216.   struct sal_chain *next;
  2217.   struct symtab_and_line sal;
  2218. };
  2219.  
  2220. #if 0
  2221. /* This isn't used; I don't know what it was for.  */
  2222. /* For each catch clause identified in ARGS, run FUNCTION
  2223.    with that clause as an argument.  */
  2224. static struct symtabs_and_lines
  2225. map_catch_names (args, function)
  2226.      char *args;
  2227.      int (*function)();
  2228. {
  2229.   register char *p = args;
  2230.   register char *p1;
  2231.   struct symtabs_and_lines sals;
  2232. #if 0
  2233.   struct sal_chain *sal_chain = 0;
  2234. #endif
  2235.  
  2236.   if (p == 0)
  2237.     error_no_arg ("one or more catch names");
  2238.  
  2239.   sals.nelts = 0;
  2240.   sals.sals = NULL;
  2241.  
  2242.   while (*p)
  2243.     {
  2244.       p1 = p;
  2245.       /* Don't swallow conditional part.  */
  2246.       if (p1[0] == 'i' && p1[1] == 'f'
  2247.       && (p1[2] == ' ' || p1[2] == '\t'))
  2248.     break;
  2249.  
  2250.       if (isalpha (*p1))
  2251.     {
  2252.       p1++;
  2253.       while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
  2254.         p1++;
  2255.     }
  2256.  
  2257.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  2258.     error ("Arguments must be catch names.");
  2259.  
  2260.       *p1 = 0;
  2261. #if 0
  2262.       if (function (p))
  2263.     {
  2264.       struct sal_chain *next
  2265.         = (struct sal_chain *)alloca (sizeof (struct sal_chain));
  2266.       next->next = sal_chain;
  2267.       next->sal = get_catch_sal (p);
  2268.       sal_chain = next;
  2269.       goto win;
  2270.     }
  2271. #endif
  2272.       printf_unfiltered ("No catch clause for exception %s.\n", p);
  2273. #if 0
  2274.     win:
  2275. #endif
  2276.       p = p1;
  2277.       while (*p == ' ' || *p == '\t') p++;
  2278.     }
  2279. }
  2280. #endif /* 0 */
  2281.  
  2282. /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
  2283.  
  2284. static struct symtabs_and_lines
  2285. get_catch_sals (this_level_only)
  2286.      int this_level_only;
  2287. {
  2288.   register struct blockvector *bl;
  2289.   register struct block *block;
  2290.   int index, have_default = 0;
  2291.   struct frame_info *fi;
  2292.   CORE_ADDR pc;
  2293.   struct symtabs_and_lines sals;
  2294.   struct sal_chain *sal_chain = 0;
  2295.   char *blocks_searched;
  2296.  
  2297.   /* Not sure whether an error message is always the correct response,
  2298.      but it's better than a core dump.  */
  2299.   if (selected_frame == NULL)
  2300.     error ("No selected frame.");
  2301.   block = get_frame_block (selected_frame);
  2302.   fi = get_frame_info (selected_frame);
  2303.   pc = fi->pc;
  2304.  
  2305.   sals.nelts = 0;
  2306.   sals.sals = NULL;
  2307.  
  2308.   if (block == 0)
  2309.     error ("No symbol table info available.\n");
  2310.  
  2311.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  2312.   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  2313.   memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  2314.  
  2315.   while (block != 0)
  2316.     {
  2317.       CORE_ADDR end = BLOCK_END (block) - 4;
  2318.       int last_index;
  2319.  
  2320.       if (bl != blockvector_for_pc (end, &index))
  2321.     error ("blockvector blotch");
  2322.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  2323.     error ("blockvector botch");
  2324.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  2325.       index += 1;
  2326.  
  2327.       /* Don't print out blocks that have gone by.  */
  2328.       while (index < last_index
  2329.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  2330.     index++;
  2331.  
  2332.       while (index < last_index
  2333.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  2334.     {
  2335.       if (blocks_searched[index] == 0)
  2336.         {
  2337.           struct block *b = BLOCKVECTOR_BLOCK (bl, index);
  2338.           int nsyms;
  2339.           register int i;
  2340.           register struct symbol *sym;
  2341.  
  2342.           nsyms = BLOCK_NSYMS (b);
  2343.  
  2344.           for (i = 0; i < nsyms; i++)
  2345.         {
  2346.           sym = BLOCK_SYM (b, i);
  2347.           if (STREQ (SYMBOL_NAME (sym), "default"))
  2348.             {
  2349.               if (have_default)
  2350.             continue;
  2351.               have_default = 1;
  2352.             }
  2353.           if (SYMBOL_CLASS (sym) == LOC_LABEL)
  2354.             {
  2355.               struct sal_chain *next = (struct sal_chain *)
  2356.             alloca (sizeof (struct sal_chain));
  2357.               next->next = sal_chain;
  2358.               next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  2359.               sal_chain = next;
  2360.             }
  2361.         }
  2362.           blocks_searched[index] = 1;
  2363.         }
  2364.       index++;
  2365.     }
  2366.       if (have_default)
  2367.     break;
  2368.       if (sal_chain && this_level_only)
  2369.     break;
  2370.  
  2371.       /* After handling the function's top-level block, stop.
  2372.      Don't continue to its superblock, the block of
  2373.      per-file symbols.  */
  2374.       if (BLOCK_FUNCTION (block))
  2375.     break;
  2376.       block = BLOCK_SUPERBLOCK (block);
  2377.     }
  2378.  
  2379.   if (sal_chain)
  2380.     {
  2381.       struct sal_chain *tmp_chain;
  2382.  
  2383.       /* Count the number of entries.  */
  2384.       for (index = 0, tmp_chain = sal_chain; tmp_chain;
  2385.        tmp_chain = tmp_chain->next)
  2386.     index++;
  2387.  
  2388.       sals.nelts = index;
  2389.       sals.sals = (struct symtab_and_line *)
  2390.     xmalloc (index * sizeof (struct symtab_and_line));
  2391.       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
  2392.     sals.sals[index] = sal_chain->sal;
  2393.     }
  2394.  
  2395.   return sals;
  2396. }
  2397.  
  2398. /* Commands to deal with catching exceptions.  */
  2399.  
  2400. static void
  2401. catch_command_1 (arg, tempflag, from_tty)
  2402.      char *arg;
  2403.      int tempflag;
  2404.      int from_tty;
  2405. {
  2406.   /* First, translate ARG into something we can deal with in terms
  2407.      of breakpoints.  */
  2408.  
  2409.   struct symtabs_and_lines sals;
  2410.   struct symtab_and_line sal;
  2411.   register struct expression *cond = 0;
  2412.   register struct breakpoint *b;
  2413.   char *save_arg;
  2414.   int i;
  2415.  
  2416.   sal.line = sal.pc = sal.end = 0;
  2417.   sal.symtab = 0;
  2418.  
  2419.   /* If no arg given, or if first arg is 'if ', all active catch clauses
  2420.      are breakpointed. */
  2421.  
  2422.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  2423.            && (arg[2] == ' ' || arg[2] == '\t')))
  2424.     {
  2425.       /* Grab all active catch clauses.  */
  2426.       sals = get_catch_sals (0);
  2427.     }
  2428.   else
  2429.     {
  2430.       /* Grab selected catch clauses.  */
  2431.       error ("catch NAME not implemented");
  2432. #if 0
  2433.       /* This isn't used; I don't know what it was for.  */
  2434.       sals = map_catch_names (arg, catch_breakpoint);
  2435. #endif
  2436.     }
  2437.  
  2438.   if (! sals.nelts) 
  2439.     return;
  2440.  
  2441.   save_arg = arg;
  2442.   for (i = 0; i < sals.nelts; i++)
  2443.     {
  2444.       resolve_sal_pc (&sals.sals[i]);
  2445.       
  2446.       while (arg && *arg)
  2447.     {
  2448.       if (arg[0] == 'i' && arg[1] == 'f'
  2449.           && (arg[2] == ' ' || arg[2] == '\t'))
  2450.         cond = parse_exp_1 ((arg += 2, &arg), 
  2451.                 block_for_pc (sals.sals[i].pc), 0);
  2452.       else
  2453.         error ("Junk at end of arguments.");
  2454.     }
  2455.       arg = save_arg;
  2456.     }
  2457.  
  2458.   for (i = 0; i < sals.nelts; i++)
  2459.     {
  2460.       sal = sals.sals[i];
  2461.  
  2462.       if (from_tty)
  2463.     describe_other_breakpoints (sal.pc);
  2464.  
  2465.       b = set_raw_breakpoint (sal);
  2466.       set_breakpoint_count (breakpoint_count + 1);
  2467.       b->number = breakpoint_count;
  2468.       b->type = bp_breakpoint;
  2469.       b->cond = cond;
  2470.       b->enable = enabled;
  2471.       b->disposition = tempflag ? delete : donttouch;
  2472.  
  2473.       mention (b);
  2474.     }
  2475.  
  2476.   if (sals.nelts > 1)
  2477.     {
  2478.       printf_unfiltered ("Multiple breakpoints were set.\n");
  2479.       printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  2480.     }
  2481.   free ((PTR)sals.sals);
  2482. }
  2483.  
  2484. #if 0
  2485. /* These aren't used; I don't know what they were for.  */
  2486. /* Disable breakpoints on all catch clauses described in ARGS.  */
  2487. static void
  2488. disable_catch (args)
  2489.      char *args;
  2490. {
  2491.   /* Map the disable command to catch clauses described in ARGS.  */
  2492. }
  2493.  
  2494. /* Enable breakpoints on all catch clauses described in ARGS.  */
  2495. static void
  2496. enable_catch (args)
  2497.      char *args;
  2498. {
  2499.   /* Map the disable command to catch clauses described in ARGS.  */
  2500. }
  2501.  
  2502. /* Delete breakpoints on all catch clauses in the active scope.  */
  2503. static void
  2504. delete_catch (args)
  2505.      char *args;
  2506. {
  2507.   /* Map the delete command to catch clauses described in ARGS.  */
  2508. }
  2509. #endif /* 0 */
  2510.  
  2511. static void
  2512. catch_command (arg, from_tty)
  2513.      char *arg;
  2514.      int from_tty;
  2515. {
  2516.   catch_command_1 (arg, 0, from_tty);
  2517. }
  2518.  
  2519. static void
  2520. clear_command (arg, from_tty)
  2521.      char *arg;
  2522.      int from_tty;
  2523. {
  2524.   register struct breakpoint *b, *b1;
  2525.   struct symtabs_and_lines sals;
  2526.   struct symtab_and_line sal;
  2527.   register struct breakpoint *found;
  2528.   int i;
  2529.  
  2530.   if (arg)
  2531.     {
  2532.       sals = decode_line_spec (arg, 1);
  2533.     }
  2534.   else
  2535.     {
  2536.       sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
  2537.       sal.line = default_breakpoint_line;
  2538.       sal.symtab = default_breakpoint_symtab;
  2539.       sal.pc = 0;
  2540.       if (sal.symtab == 0)
  2541.     error ("No source file specified.");
  2542.  
  2543.       sals.sals[0] = sal;
  2544.       sals.nelts = 1;
  2545.     }
  2546.  
  2547.   for (i = 0; i < sals.nelts; i++)
  2548.     {
  2549.       /* If exact pc given, clear bpts at that pc.
  2550.      But if sal.pc is zero, clear all bpts on specified line.  */
  2551.       sal = sals.sals[i];
  2552.       found = (struct breakpoint *) 0;
  2553.       while (breakpoint_chain
  2554.          && (sal.pc
  2555.          ? breakpoint_chain->address == sal.pc
  2556.          : (breakpoint_chain->source_file != NULL
  2557.             && sal.symtab != NULL
  2558.             && STREQ (breakpoint_chain->source_file,
  2559.                   sal.symtab->filename)
  2560.             && breakpoint_chain->line_number == sal.line)))
  2561.     {
  2562.       b1 = breakpoint_chain;
  2563.       breakpoint_chain = b1->next;
  2564.       b1->next = found;
  2565.       found = b1;
  2566.     }
  2567.  
  2568.       ALL_BREAKPOINTS (b)
  2569.     while (b->next
  2570.            && b->next->type != bp_watchpoint
  2571.            && (sal.pc
  2572.            ? b->next->address == sal.pc
  2573.            : (b->next->source_file != NULL
  2574.               && sal.symtab != NULL
  2575.               && STREQ (b->next->source_file, sal.symtab->filename)
  2576.               && b->next->line_number == sal.line)))
  2577.       {
  2578.         b1 = b->next;
  2579.         b->next = b1->next;
  2580.         b1->next = found;
  2581.         found = b1;
  2582.       }
  2583.  
  2584.       if (found == 0)
  2585.     {
  2586.       if (arg)
  2587.         error ("No breakpoint at %s.", arg);
  2588.       else
  2589.         error ("No breakpoint at this line.");
  2590.     }
  2591.  
  2592.       if (found->next) from_tty = 1; /* Always report if deleted more than one */
  2593.       if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
  2594.       while (found)
  2595.     {
  2596.       if (from_tty) printf_unfiltered ("%d ", found->number);
  2597.       b1 = found->next;
  2598.       delete_breakpoint (found);
  2599.       found = b1;
  2600.     }
  2601.       if (from_tty) putchar_unfiltered ('\n');
  2602.     }
  2603.   free ((PTR)sals.sals);
  2604. }
  2605.  
  2606. /* Delete breakpoint in BS if they are `delete' breakpoints.
  2607.    This is called after any breakpoint is hit, or after errors.  */
  2608.  
  2609. void
  2610. breakpoint_auto_delete (bs)
  2611.      bpstat bs;
  2612. {
  2613.   for (; bs; bs = bs->next)
  2614.     if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete
  2615.     && bs->stop)
  2616.       delete_breakpoint (bs->breakpoint_at);
  2617. }
  2618.  
  2619. /* Delete a breakpoint and clean up all traces of it in the data structures. */
  2620.  
  2621. void
  2622. delete_breakpoint (bpt)
  2623.      struct breakpoint *bpt;
  2624. {
  2625.   register struct breakpoint *b;
  2626.   register bpstat bs;
  2627.  
  2628.   if (bpt->inserted)
  2629.     target_remove_breakpoint(bpt->address, bpt->shadow_contents);
  2630.  
  2631.   if (breakpoint_chain == bpt)
  2632.     breakpoint_chain = bpt->next;
  2633.  
  2634.   ALL_BREAKPOINTS (b)
  2635.     if (b->next == bpt)
  2636.       {
  2637.     b->next = bpt->next;
  2638.     break;
  2639.       }
  2640.  
  2641.   check_duplicates (bpt->address);
  2642.   /* If this breakpoint was inserted, and there is another breakpoint
  2643.      at the same address, we need to insert the other breakpoint.  */
  2644.   if (bpt->inserted)
  2645.     {
  2646.       ALL_BREAKPOINTS (b)
  2647.     if (b->address == bpt->address
  2648.         && !b->duplicate
  2649.         && b->enable != disabled)
  2650.       {
  2651.         int val;
  2652.         val = target_insert_breakpoint (b->address, b->shadow_contents);
  2653.         if (val != 0)
  2654.           {
  2655.         target_terminal_ours_for_output ();
  2656.         fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number);
  2657.         memory_error (val, b->address);    /* which bombs us out */
  2658.           }
  2659.         else
  2660.           b->inserted = 1;
  2661.       }
  2662.     }
  2663.  
  2664.   free_command_lines (&bpt->commands);
  2665.   if (bpt->cond)
  2666.     free (bpt->cond);
  2667.   if (bpt->cond_string != NULL)
  2668.     free (bpt->cond_string);
  2669.   if (bpt->addr_string != NULL)
  2670.     free (bpt->addr_string);
  2671.   if (bpt->exp_string != NULL)
  2672.     free (bpt->exp_string);
  2673.   if (bpt->source_file != NULL)
  2674.     free (bpt->source_file);
  2675.  
  2676.   if (xgdb_verbose && bpt->type == bp_breakpoint)
  2677.     {
  2678.       target_terminal_ours_for_output ();
  2679.       printf_unfiltered ("breakpoint #%d deleted\n", bpt->number);
  2680.     }
  2681.  
  2682.   /* Be sure no bpstat's are pointing at it after it's been freed.  */
  2683.   /* FIXME, how can we find all bpstat's?
  2684.      We just check stop_bpstat for now.  */
  2685.   for (bs = stop_bpstat; bs; bs = bs->next)
  2686.     if (bs->breakpoint_at == bpt)
  2687.       bs->breakpoint_at = NULL;
  2688.   free ((PTR)bpt);
  2689. }
  2690.  
  2691. static void
  2692. delete_command (arg, from_tty)
  2693.      char *arg;
  2694.      int from_tty;
  2695. {
  2696.  
  2697.   if (arg == 0)
  2698.     {
  2699.       /* Ask user only if there are some breakpoints to delete.  */
  2700.       if (!from_tty
  2701.       || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
  2702.     {
  2703.       /* No arg; clear all breakpoints.  */
  2704.       while (breakpoint_chain)
  2705.         delete_breakpoint (breakpoint_chain);
  2706.     }
  2707.     }
  2708.   else
  2709.     map_breakpoint_numbers (arg, delete_breakpoint);
  2710. }
  2711.  
  2712. /* Reset a breakpoint given it's struct breakpoint * BINT.
  2713.    The value we return ends up being the return value from catch_errors.
  2714.    Unused in this case.  */
  2715.  
  2716. static int
  2717. breakpoint_re_set_one (bint)
  2718.      char *bint;
  2719. {
  2720.   struct breakpoint *b = (struct breakpoint *)bint;  /* get past catch_errs */
  2721.   int i;
  2722.   struct symtabs_and_lines sals;
  2723.   char *s;
  2724.   enum enable save_enable;
  2725.  
  2726.   switch (b->type)
  2727.     {
  2728.     case bp_breakpoint:
  2729.       if (b->addr_string == NULL)
  2730.     {
  2731.       /* Anything without a string can't be re-set. */
  2732.       delete_breakpoint (b);
  2733.       return 0;
  2734.     }
  2735.       /* In case we have a problem, disable this breakpoint.  We'll restore
  2736.      its status if we succeed.  */
  2737.       save_enable = b->enable;
  2738.       b->enable = disabled;
  2739.  
  2740.       s = b->addr_string;
  2741.       sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL);
  2742.       for (i = 0; i < sals.nelts; i++)
  2743.     {
  2744.       resolve_sal_pc (&sals.sals[i]);
  2745.  
  2746.       /* Reparse conditions, they might contain references to the
  2747.          old symtab.  */
  2748.       if (b->cond_string != NULL)
  2749.         {
  2750.           s = b->cond_string;
  2751.           if (b->cond)
  2752.         free ((PTR)b->cond);
  2753.           b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
  2754.         }
  2755.  
  2756.       /* We need to re-set the breakpoint if the address changes...*/
  2757.       if (b->address != sals.sals[i].pc
  2758.           /* ...or new and old breakpoints both have source files, and
  2759.          the source file name or the line number changes...  */
  2760.           || (b->source_file != NULL
  2761.           && sals.sals[i].symtab != NULL
  2762.           && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
  2763.               || b->line_number != sals.sals[i].line)
  2764.           )
  2765.           /* ...or we switch between having a source file and not having
  2766.          one.  */
  2767.           || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
  2768.           )
  2769.         {
  2770.           if (b->source_file != NULL)
  2771.         free (b->source_file);
  2772.           if (sals.sals[i].symtab == NULL)
  2773.         b->source_file = NULL;
  2774.           else
  2775.         b->source_file =
  2776.           savestring (sals.sals[i].symtab->filename,
  2777.                   strlen (sals.sals[i].symtab->filename));
  2778.           b->line_number = sals.sals[i].line;
  2779.           b->address = sals.sals[i].pc;
  2780.       
  2781.           check_duplicates (b->address);
  2782.  
  2783.           mention (b);
  2784.         }
  2785.       b->enable = save_enable;    /* Restore it, this worked. */
  2786.     }
  2787.       free ((PTR)sals.sals);
  2788.       break;
  2789.  
  2790.     case bp_watchpoint:
  2791.       innermost_block = NULL;
  2792.       /* The issue arises of what context to evaluate this in.  The same
  2793.      one as when it was set, but what does that mean when symbols have
  2794.      been re-read?  We could save the filename and functionname, but
  2795.      if the context is more local than that, the best we could do would
  2796.      be something like how many levels deep and which index at that
  2797.      particular level, but that's going to be less stable than filenames
  2798.      or functionnames.  */
  2799.       /* So for now, just use a global context.  */
  2800.       b->exp = parse_expression (b->exp_string);
  2801.       b->exp_valid_block = innermost_block;
  2802.       b->val = evaluate_expression (b->exp);
  2803.       release_value (b->val);
  2804.       if (VALUE_LAZY (b->val))
  2805.     value_fetch_lazy (b->val);
  2806.  
  2807.       if (b->cond_string != NULL)
  2808.     {
  2809.       s = b->cond_string;
  2810.       b->cond = parse_exp_1 (&s, (struct block *)0, 0);
  2811.     }
  2812.       if (b->enable == enabled)
  2813.     mention (b);
  2814.       break;
  2815.  
  2816.     default:
  2817.       printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
  2818.       /* fall through */
  2819.     case bp_until:
  2820.     case bp_finish:
  2821.     case bp_longjmp:
  2822.     case bp_longjmp_resume:
  2823.     case bp_call_dummy:
  2824.       delete_breakpoint (b);
  2825.       break;
  2826.     }
  2827.  
  2828.   return 0;
  2829. }
  2830.  
  2831. /* Re-set all breakpoints after symbols have been re-loaded.  */
  2832. void
  2833. breakpoint_re_set ()
  2834. {
  2835.   struct breakpoint *b, *temp;
  2836.   static char message1[] = "Error in re-setting breakpoint %d:\n";
  2837.   char message[sizeof (message1) + 30 /* slop */];
  2838.   
  2839.   ALL_BREAKPOINTS_SAFE (b, temp)
  2840.     {
  2841.       sprintf (message, message1, b->number);    /* Format possible error msg */
  2842.       catch_errors (breakpoint_re_set_one, (char *) b, message,
  2843.             RETURN_MASK_ALL);
  2844.     }
  2845.  
  2846.   create_longjmp_breakpoint("longjmp");
  2847.   create_longjmp_breakpoint("_longjmp");
  2848.   create_longjmp_breakpoint("siglongjmp");
  2849.   create_longjmp_breakpoint(NULL);
  2850.  
  2851. #if 0
  2852.   /* Took this out (temporaliy at least), since it produces an extra 
  2853.      blank line at startup. This messes up the gdbtests. -PB */
  2854.   /* Blank line to finish off all those mention() messages we just printed.  */
  2855.   printf_filtered ("\n");
  2856. #endif
  2857. }
  2858.  
  2859. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  2860.    If from_tty is nonzero, it prints a message to that effect,
  2861.    which ends with a period (no newline).  */
  2862.  
  2863. void
  2864. set_ignore_count (bptnum, count, from_tty)
  2865.      int bptnum, count, from_tty;
  2866. {
  2867.   register struct breakpoint *b;
  2868.  
  2869.   if (count < 0)
  2870.     count = 0;
  2871.  
  2872.   ALL_BREAKPOINTS (b)
  2873.     if (b->number == bptnum)
  2874.       {
  2875.     b->ignore_count = count;
  2876.     if (!from_tty)
  2877.       return;
  2878.     else if (count == 0)
  2879.       printf_filtered ("Will stop next time breakpoint %d is reached.",
  2880.                bptnum);
  2881.     else if (count == 1)
  2882.       printf_filtered ("Will ignore next crossing of breakpoint %d.",
  2883.                bptnum);
  2884.     else
  2885.       printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
  2886.           count, bptnum);
  2887.     return;
  2888.       }
  2889.  
  2890.   error ("No breakpoint number %d.", bptnum);
  2891. }
  2892.  
  2893. /* Clear the ignore counts of all breakpoints.  */
  2894. void
  2895. breakpoint_clear_ignore_counts ()
  2896. {
  2897.   struct breakpoint *b;
  2898.  
  2899.   ALL_BREAKPOINTS (b)
  2900.     b->ignore_count = 0;
  2901. }
  2902.  
  2903. /* Command to set ignore-count of breakpoint N to COUNT.  */
  2904.  
  2905. static void
  2906. ignore_command (args, from_tty)
  2907.      char *args;
  2908.      int from_tty;
  2909. {
  2910.   char *p = args;
  2911.   register int num;
  2912.  
  2913.   if (p == 0)
  2914.     error_no_arg ("a breakpoint number");
  2915.   
  2916.   num = get_number (&p);
  2917.  
  2918.   if (*p == 0)
  2919.     error ("Second argument (specified ignore-count) is missing.");
  2920.  
  2921.   set_ignore_count (num,
  2922.             longest_to_int (value_as_long (parse_and_eval (p))),
  2923.             from_tty);
  2924.   printf_filtered ("\n");
  2925. }
  2926.  
  2927. /* Call FUNCTION on each of the breakpoints
  2928.    whose numbers are given in ARGS.  */
  2929.  
  2930. static void
  2931. map_breakpoint_numbers (args, function)
  2932.      char *args;
  2933.      void (*function) PARAMS ((struct breakpoint *));
  2934. {
  2935.   register char *p = args;
  2936.   char *p1;
  2937.   register int num;
  2938.   register struct breakpoint *b;
  2939.  
  2940.   if (p == 0)
  2941.     error_no_arg ("one or more breakpoint numbers");
  2942.  
  2943.   while (*p)
  2944.     {
  2945.       p1 = p;
  2946.       
  2947.       num = get_number (&p1);
  2948.  
  2949.       ALL_BREAKPOINTS (b)
  2950.     if (b->number == num)
  2951.       {
  2952.         function (b);
  2953.         goto win;
  2954.       }
  2955.       printf_unfiltered ("No breakpoint number %d.\n", num);
  2956.     win:
  2957.       p = p1;
  2958.     }
  2959. }
  2960.  
  2961. static void
  2962. enable_breakpoint (bpt)
  2963.      struct breakpoint *bpt;
  2964. {
  2965.   FRAME save_selected_frame = NULL;
  2966.   int save_selected_frame_level = -1;
  2967.   
  2968.   bpt->enable = enabled;
  2969.  
  2970.   if (xgdb_verbose && bpt->type == bp_breakpoint)
  2971.     printf_unfiltered ("breakpoint #%d enabled\n", bpt->number);
  2972.  
  2973.   check_duplicates (bpt->address);
  2974.   if (bpt->type == bp_watchpoint)
  2975.     {
  2976.       if (bpt->exp_valid_block != NULL)
  2977.     {
  2978.       FRAME fr = within_scope (bpt->exp_valid_block);
  2979.       if (fr == NULL)
  2980.         {
  2981.           printf_filtered ("\
  2982. Cannot enable watchpoint %d because the block in which its expression\n\
  2983. is valid is not currently in scope.\n", bpt->number);
  2984.           bpt->enable = disabled;
  2985.           return;
  2986.         }
  2987.       save_selected_frame = selected_frame;
  2988.       save_selected_frame_level = selected_frame_level;
  2989.       select_frame (fr, -1);
  2990.     }
  2991.  
  2992.       value_free (bpt->val);
  2993.  
  2994.       bpt->val = evaluate_expression (bpt->exp);
  2995.       release_value (bpt->val);
  2996.       if (VALUE_LAZY (bpt->val))
  2997.     value_fetch_lazy (bpt->val);
  2998.  
  2999.       if (save_selected_frame_level >= 0)
  3000.     select_frame (save_selected_frame, save_selected_frame_level);
  3001.     }
  3002. }
  3003.  
  3004. /* ARGSUSED */
  3005. static void
  3006. enable_command (args, from_tty)
  3007.      char *args;
  3008.      int from_tty;
  3009. {
  3010.   struct breakpoint *bpt;
  3011.   if (args == 0)
  3012.     ALL_BREAKPOINTS (bpt)
  3013.       switch (bpt->type)
  3014.     {
  3015.     case bp_breakpoint:
  3016.     case bp_watchpoint:
  3017.       enable_breakpoint (bpt);
  3018.     default:
  3019.       continue;
  3020.     }
  3021.   else
  3022.     map_breakpoint_numbers (args, enable_breakpoint);
  3023. }
  3024.  
  3025. static void
  3026. disable_breakpoint (bpt)
  3027.      struct breakpoint *bpt;
  3028. {
  3029.   bpt->enable = disabled;
  3030.  
  3031.   if (xgdb_verbose && bpt->type == bp_breakpoint)
  3032.     printf_filtered ("breakpoint #%d disabled\n", bpt->number);
  3033.  
  3034.   check_duplicates (bpt->address);
  3035. }
  3036.  
  3037. /* ARGSUSED */
  3038. static void
  3039. disable_command (args, from_tty)
  3040.      char *args;
  3041.      int from_tty;
  3042. {
  3043.   register struct breakpoint *bpt;
  3044.   if (args == 0)
  3045.     ALL_BREAKPOINTS (bpt)
  3046.       switch (bpt->type)
  3047.     {
  3048.     case bp_breakpoint:
  3049.     case bp_watchpoint:
  3050.       disable_breakpoint (bpt);
  3051.     default:
  3052.       continue;
  3053.     }
  3054.   else
  3055.     map_breakpoint_numbers (args, disable_breakpoint);
  3056. }
  3057.  
  3058. static void
  3059. enable_once_breakpoint (bpt)
  3060.      struct breakpoint *bpt;
  3061. {
  3062.   bpt->enable = enabled;
  3063.   bpt->disposition = disable;
  3064.  
  3065.   check_duplicates (bpt->address);
  3066. }
  3067.  
  3068. /* ARGSUSED */
  3069. static void
  3070. enable_once_command (args, from_tty)
  3071.      char *args;
  3072.      int from_tty;
  3073. {
  3074.   map_breakpoint_numbers (args, enable_once_breakpoint);
  3075. }
  3076.  
  3077. static void
  3078. enable_delete_breakpoint (bpt)
  3079.      struct breakpoint *bpt;
  3080. {
  3081.   bpt->enable = enabled;
  3082.   bpt->disposition = delete;
  3083.  
  3084.   check_duplicates (bpt->address);
  3085. }
  3086.  
  3087. /* ARGSUSED */
  3088. static void
  3089. enable_delete_command (args, from_tty)
  3090.      char *args;
  3091.      int from_tty;
  3092. {
  3093.   map_breakpoint_numbers (args, enable_delete_breakpoint);
  3094. }
  3095.  
  3096. /*
  3097.  * Use default_breakpoint_'s, or nothing if they aren't valid.
  3098.  */
  3099. struct symtabs_and_lines
  3100. decode_line_spec_1 (string, funfirstline)
  3101.      char *string;
  3102.      int funfirstline;
  3103. {
  3104.   struct symtabs_and_lines sals;
  3105.   if (string == 0)
  3106.     error ("Empty line specification.");
  3107.   if (default_breakpoint_valid)
  3108.     sals = decode_line_1 (&string, funfirstline,
  3109.               default_breakpoint_symtab, default_breakpoint_line,
  3110.               (char ***)NULL);
  3111.   else
  3112.     sals = decode_line_1 (&string, funfirstline,
  3113.               (struct symtab *)NULL, 0, (char ***)NULL);
  3114.   if (*string)
  3115.     error ("Junk at end of line specification: %s", string);
  3116.   return sals;
  3117. }
  3118.  
  3119. void
  3120. _initialize_breakpoint ()
  3121. {
  3122.   breakpoint_chain = 0;
  3123.   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
  3124.      before a breakpoint is set.  */
  3125.   breakpoint_count = 0;
  3126.  
  3127.   add_com ("ignore", class_breakpoint, ignore_command,
  3128.        "Set ignore-count of breakpoint number N to COUNT.");
  3129.  
  3130.   add_com ("commands", class_breakpoint, commands_command,
  3131.        "Set commands to be executed when a breakpoint is hit.\n\
  3132. Give breakpoint number as argument after \"commands\".\n\
  3133. With no argument, the targeted breakpoint is the last one set.\n\
  3134. The commands themselves follow starting on the next line.\n\
  3135. Type a line containing \"end\" to indicate the end of them.\n\
  3136. Give \"silent\" as the first line to make the breakpoint silent;\n\
  3137. then no output is printed when it is hit, except what the commands print.");
  3138.  
  3139.   add_com ("condition", class_breakpoint, condition_command,
  3140.        "Specify breakpoint number N to break only if COND is true.\n\
  3141. N is an integer; COND is an expression to be evaluated whenever\n\
  3142. breakpoint N is reached.  ");
  3143.  
  3144.   add_com ("tbreak", class_breakpoint, tbreak_command,
  3145.        "Set a temporary breakpoint.  Args like \"break\" command.\n\
  3146. Like \"break\" except the breakpoint is only enabled temporarily,\n\
  3147. so it will be disabled when hit.  Equivalent to \"break\" followed\n\
  3148. by using \"enable once\" on the breakpoint number.");
  3149.  
  3150.   add_prefix_cmd ("enable", class_breakpoint, enable_command,
  3151.           "Enable some breakpoints.\n\
  3152. Give breakpoint numbers (separated by spaces) as arguments.\n\
  3153. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  3154. This is used to cancel the effect of the \"disable\" command.\n\
  3155. With a subcommand you can enable temporarily.",
  3156.           &enablelist, "enable ", 1, &cmdlist);
  3157.  
  3158.   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
  3159.           "Enable some breakpoints.\n\
  3160. Give breakpoint numbers (separated by spaces) as arguments.\n\
  3161. This is used to cancel the effect of the \"disable\" command.\n\
  3162. May be abbreviated to simply \"enable\".\n",
  3163.           &enablebreaklist, "enable breakpoints ", 1, &enablelist);
  3164.  
  3165.   add_cmd ("once", no_class, enable_once_command,
  3166.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  3167. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  3168. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  3169.        &enablebreaklist);
  3170.  
  3171.   add_cmd ("delete", no_class, enable_delete_command,
  3172.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  3173. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  3174.        &enablebreaklist);
  3175.  
  3176.   add_cmd ("delete", no_class, enable_delete_command,
  3177.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  3178. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  3179.        &enablelist);
  3180.  
  3181.   add_cmd ("once", no_class, enable_once_command,
  3182.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  3183. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  3184. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  3185.        &enablelist);
  3186.  
  3187.   add_prefix_cmd ("disable", class_breakpoint, disable_command,
  3188.        "Disable some breakpoints.\n\
  3189. Arguments are breakpoint numbers with spaces in between.\n\
  3190. To disable all breakpoints, give no argument.\n\
  3191. A disabled breakpoint is not forgotten, but has no effect until reenabled.",
  3192.           &disablelist, "disable ", 1, &cmdlist);
  3193.   add_com_alias ("dis", "disable", class_breakpoint, 1);
  3194.   add_com_alias ("disa", "disable", class_breakpoint, 1);
  3195.  
  3196.   add_cmd ("breakpoints", class_alias, disable_command,
  3197.        "Disable some breakpoints.\n\
  3198. Arguments are breakpoint numbers with spaces in between.\n\
  3199. To disable all breakpoints, give no argument.\n\
  3200. A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
  3201. This command may be abbreviated \"disable\".",
  3202.        &disablelist);
  3203.  
  3204.   add_prefix_cmd ("delete", class_breakpoint, delete_command,
  3205.        "Delete some breakpoints or auto-display expressions.\n\
  3206. Arguments are breakpoint numbers with spaces in between.\n\
  3207. To delete all breakpoints, give no argument.\n\
  3208. \n\
  3209. Also a prefix command for deletion of other GDB objects.\n\
  3210. The \"unset\" command is also an alias for \"delete\".",
  3211.           &deletelist, "delete ", 1, &cmdlist);
  3212.   add_com_alias ("d", "delete", class_breakpoint, 1);
  3213.  
  3214.   add_cmd ("breakpoints", class_alias, delete_command,
  3215.        "Delete some breakpoints or auto-display expressions.\n\
  3216. Arguments are breakpoint numbers with spaces in between.\n\
  3217. To delete all breakpoints, give no argument.\n\
  3218. This command may be abbreviated \"delete\".",
  3219.        &deletelist);
  3220.  
  3221.   add_com ("clear", class_breakpoint, clear_command,
  3222.        "Clear breakpoint at specified line or function.\n\
  3223. Argument may be line number, function name, or \"*\" and an address.\n\
  3224. If line number is specified, all breakpoints in that line are cleared.\n\
  3225. If function is specified, breakpoints at beginning of function are cleared.\n\
  3226. If an address is specified, breakpoints at that address are cleared.\n\n\
  3227. With no argument, clears all breakpoints in the line that the selected frame\n\
  3228. is executing in.\n\
  3229. \n\
  3230. See also the \"delete\" command which clears breakpoints by number.");
  3231.  
  3232.   add_com ("break", class_breakpoint, break_command,
  3233.        "Set breakpoint at specified line or function.\n\
  3234. Argument may be line number, function name, or \"*\" and an address.\n\
  3235. If line number is specified, break at start of code for that line.\n\
  3236. If function is specified, break at start of code for that function.\n\
  3237. If an address is specified, break at that exact address.\n\
  3238. With no arg, uses current execution address of selected stack frame.\n\
  3239. This is useful for breaking on return to a stack frame.\n\
  3240. \n\
  3241. Multiple breakpoints at one place are permitted, and useful if conditional.\n\
  3242. \n\
  3243. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  3244.   add_com_alias ("b", "break", class_run, 1);
  3245.   add_com_alias ("br", "break", class_run, 1);
  3246.   add_com_alias ("bre", "break", class_run, 1);
  3247.   add_com_alias ("brea", "break", class_run, 1);
  3248.  
  3249.   add_info ("breakpoints", breakpoints_info,
  3250.         "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
  3251. The \"Type\" column indicates one of:\n\
  3252. \tbreakpoint     - normal breakpoint\n\
  3253. \twatchpoint     - watchpoint\n\
  3254. The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  3255. the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
  3256. breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
  3257. address and file/line number respectively.\n\n\
  3258. Convenience variable \"$_\" and default examine address for \"x\"\n\
  3259. are set to the address of the last breakpoint listed.\n\n\
  3260. Convenience variable \"$bpnum\" contains the number of the last\n\
  3261. breakpoint set.");
  3262.  
  3263. #if MAINTENANCE_CMDS
  3264.  
  3265.   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
  3266.         "Status of all breakpoints, or breakpoint number NUMBER.\n\
  3267. The \"Type\" column indicates one of:\n\
  3268. \tbreakpoint     - normal breakpoint\n\
  3269. \twatchpoint     - watchpoint\n\
  3270. \tlongjmp        - internal breakpoint used to step through longjmp()\n\
  3271. \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
  3272. \tuntil          - internal breakpoint used by the \"until\" command\n\
  3273. \tfinish         - internal breakpoint used by the \"finish\" command\n\
  3274. The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
  3275. the disposition of the breakpoint after it gets hit.  \"dis\" means that the\n\
  3276. breakpoint will be disabled.  The \"Address\" and \"What\" columns indicate the\n\
  3277. address and file/line number respectively.\n\n\
  3278. Convenience variable \"$_\" and default examine address for \"x\"\n\
  3279. are set to the address of the last breakpoint listed.\n\n\
  3280. Convenience variable \"$bpnum\" contains the number of the last\n\
  3281. breakpoint set.",
  3282.        &maintenanceinfolist);
  3283.  
  3284. #endif    /* MAINTENANCE_CMDS */
  3285.  
  3286.   add_com ("catch", class_breakpoint, catch_command,
  3287.          "Set breakpoints to catch exceptions that are raised.\n\
  3288. Argument may be a single exception to catch, multiple exceptions\n\
  3289. to catch, or the default exception \"default\".  If no arguments\n\
  3290. are given, breakpoints are set at all exception handlers catch clauses\n\
  3291. within the current scope.\n\
  3292. \n\
  3293. A condition specified for the catch applies to all breakpoints set\n\
  3294. with this command\n\
  3295. \n\
  3296. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  3297.  
  3298.   add_com ("watch", class_breakpoint, watch_command,
  3299.        "Set a watchpoint for an expression.\n\
  3300. A watchpoint stops execution of your program whenever the value of\n\
  3301. an expression changes.");
  3302.  
  3303.   add_info ("watchpoints", breakpoints_info,
  3304.         "Synonym for ``info breakpoints''.");
  3305. }
  3306.  
  3307. /* OK, when we call objfile_relocate, we need to relocate breakpoints
  3308.    too.  breakpoint_re_set is not a good choice--for example, if
  3309.    addr_string contains just a line number without a file name the
  3310.    breakpoint might get set in a different file.  In general, there is
  3311.    no need to go all the way back to the user's string (though this might
  3312.    work if some effort were made to canonicalize it), since symtabs and
  3313.    everything except addresses are still valid.
  3314.  
  3315.    Probably the best way to solve this is to have each breakpoint save
  3316.    the objfile and the section number that was used to set it (if set
  3317.    by "*addr", probably it is best to use find_pc_line to get a symtab
  3318.    and use the objfile and block_line_section for that symtab).  Then
  3319.    objfile_relocate can call fixup_breakpoints with the objfile and
  3320.    the new_offsets, and it can relocate only the appropriate breakpoints.  */
  3321.  
  3322. #ifdef IBM6000_TARGET
  3323. /* But for now, just kludge it based on the concept that before an
  3324.    objfile is relocated the breakpoint is below 0x10000000, and afterwards
  3325.    it is higher, so that way we only relocate each breakpoint once.  */
  3326.  
  3327. void
  3328. fixup_breakpoints (low, high, delta)
  3329.   CORE_ADDR low;
  3330.   CORE_ADDR high;
  3331.   CORE_ADDR delta;
  3332. {
  3333.   struct breakpoint *b;
  3334.  
  3335.   ALL_BREAKPOINTS (b)
  3336.     {
  3337.      if (b->address >= low && b->address <= high)
  3338.        b->address += delta;
  3339.     }
  3340. }
  3341. #endif
  3342.